You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+91-8Lines changed: 91 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -485,16 +485,48 @@ them may cause you more headache than necessary.
485
485
486
486
#### URL intent filter
487
487
488
-
Extensions can define URL intent filters by defining it inside a custom `AndroidManifest.xml` file.
489
-
(Example TBD.)
488
+
Extensions can define a URL pattern so that these URLs can be opened in Mihon.
489
+
490
+
To do this, you need two files:
491
+
- `AndroidManifest.xml` which must be placed in the root directory of your extension (Example: `src/id/riztranslation/AndroidManifest.xml`)
492
+
- `UrlActivity.kt` which should be placed next to your main file. (Example: `src/id/riztranslation/src/eu/kanade/tachiyomi/extension/id/riztranslation/UrlActivity.kt`)
To test if the URL intent filter is working as expected, you can try opening the website in a browser
492
-
and navigating to the endpoint that was added as a filter or clicking a hyperlink. Alternatively,
493
-
you can use the `adb` command below.
525
+
The `AndroidManifest.xml` file will contain an `android:name` attribute that refers to the “path” of your `UrlActivity.kt` file. For example, if the extension is Riztranslation, the `android:name` will be `.id.riztranslation.UrlActivity`.
494
526
495
-
```console
496
-
$ adb shell am start -d "<your-link>" -a android.intent.action.VIEW
497
-
```
527
+
Next, you have the `<data android:scheme=“https” android:host=“host” android:pathPattern=“/..*” />` element; you can have it multiple times, which allows you to specify the URL that can be opened in Mihon. You can read more about this [here](https://developer.android.com/guide/topics/manifest/data-element).
528
+
529
+
Now, as for `UrlActivity`, you can just use the example below.
498
530
499
531
> [!CAUTION]
500
532
> The activity does not support any Kotlin Intrinsics specific methods or calls,
@@ -504,6 +536,57 @@ $ adb shell am start -d "<your-link>" -a android.intent.action.VIEW
504
536
> You can use Kotlin Intrinsics in the extension source class, this limitation only
505
537
> applies to the activity classes.
506
538
539
+
To explain how it works, it will trigger Mihon's `SEARCH` action, passing the URL as a query and specifying that it comes from your extension to narrow down the search. Avoid putting any logic in this file; instead, implement it in your extension's class.
540
+
541
+
```kotlin
542
+
class UrlActivity : Activity() {
543
+
override fun onCreate(savedInstanceState: Bundle?) {
544
+
super.onCreate(savedInstanceState)
545
+
val intentData = intent?.data?.toString()
546
+
if (intentData != null) {
547
+
val mainIntent = Intent().apply {
548
+
action = "eu.kanade.tachiyomi.SEARCH"
549
+
putExtra("query", intentData)
550
+
putExtra("filter", packageName)
551
+
}
552
+
try {
553
+
startActivity(mainIntent)
554
+
} catch (e: ActivityNotFoundException) {
555
+
Log.e("RiztranslationUrl", e.toString())
556
+
}
557
+
} else {
558
+
Log.e("RiztranslationUrl", "could not parse uri from intent $intent")
559
+
}
560
+
561
+
finish()
562
+
exitProcess(0)
563
+
}
564
+
}
565
+
```
566
+
567
+
Now all you need to do is adapt the search function (`fetchSearchManga`) in your extension so that, given a URL, it returns a single manga that matches that URL. For example:
568
+
```kotlin
569
+
if (query.startsWith("https://")) {
570
+
val url = query.toHttpUrlOrNull()
571
+
if (url != null && url.host == baseUrl.toHttpUrl().host) {
572
+
val typeIndex = url.pathSegments.indexOfFirst { it == "detail" || it == "view" }
To test if the URL intent filter is working as expected, you can try opening the website in a browser
582
+
and navigating to the endpoint that was added as a filter or clicking a hyperlink. Alternatively,
583
+
you can use the `adb` command below.
584
+
585
+
```console
586
+
$ adb shell am start -d "<your-link>" -a android.intent.action.VIEW
587
+
```
588
+
You can find a complete example of how URLs work in the [Riztranslation extension](https://github.com/keiyoushi/extensions-source/tree/main/src/id/riztranslation).
589
+
507
590
#### Update strategy
508
591
509
592
There is some cases where titles in a source will always only have the same chapter list
0 commit comments