Skip to content

Commit d693e52

Browse files
authored
feat(android): add onNewIntent plugin hook (#6780)
1 parent 2a5175a commit d693e52

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

.changes/on-new-intent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Added the `onNewIntent` Plugin hook on Android.

core/tauri/mobile/android/src/main/java/app/tauri/plugin/Plugin.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ abstract class Plugin(private val activity: Activity) {
3030
return handle!!.config
3131
}
3232

33+
/**
34+
* Handle a new intent being received by the application
35+
*/
36+
open fun onNewIntent(intent: Intent) {}
37+
3338
/**
3439
* Start activity for result with the provided Intent and resolve calling the provided callback method name.
3540
*

core/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginHandle.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import app.tauri.annotation.Command
1717
import app.tauri.annotation.TauriPlugin
1818
import java.lang.reflect.Method
1919

20-
class PluginHandle(private val manager: PluginManager, val name: String, private val instance: Plugin, val config: JSObject) {
20+
class PluginHandle(private val manager: PluginManager, val name: String, val instance: Plugin, val config: JSObject) {
2121
private val commands: HashMap<String, CommandData> = HashMap()
2222
private val permissionCallbackMethods: HashMap<String, Method> = HashMap()
2323
private val startActivityCallbackMethods: HashMap<String, Method> = HashMap()

core/tauri/mobile/android/src/main/java/app/tauri/plugin/PluginManager.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class PluginManager(val activity: AppCompatActivity) {
4646
}
4747
}
4848

49+
fun onNewIntent(intent: Intent) {
50+
for (plugin in plugins.values) {
51+
plugin.instance.onNewIntent(intent)
52+
}
53+
}
54+
4955
fun startActivityForResult(intent: Intent, callback: ActivityResultCallback) {
5056
startActivityForResultCallback = callback
5157
startActivityForResultLauncher.launch(intent)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package {{reverse-domain app.domain}}.{{snake-case app.name}}
22

3+
import android.os.Bundle
34
import app.tauri.plugin.PluginManager
45

56
abstract class TauriActivity : WryActivity() {
67
var pluginManager: PluginManager = PluginManager(this)
8+
9+
override fun onCreate(savedInstanceState: Bundle?) {
10+
super.onCreate(savedInstanceState)
11+
if (intent != null) {
12+
pluginManager.onNewIntent(intent)
13+
}
14+
}
715
}

0 commit comments

Comments
 (0)