mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-01 15:36:14 +03:00
feat(android): add onNewIntent
plugin hook (#6780)
This commit is contained in:
parent
2a5175a8f8
commit
d693e526e8
5
.changes/on-new-intent.md
Normal file
5
.changes/on-new-intent.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Added the `onNewIntent` Plugin hook on Android.
|
@ -30,6 +30,11 @@ abstract class Plugin(private val activity: Activity) {
|
||||
return handle!!.config
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a new intent being received by the application
|
||||
*/
|
||||
open fun onNewIntent(intent: Intent) {}
|
||||
|
||||
/**
|
||||
* Start activity for result with the provided Intent and resolve calling the provided callback method name.
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
import java.lang.reflect.Method
|
||||
|
||||
class PluginHandle(private val manager: PluginManager, val name: String, private val instance: Plugin, val config: JSObject) {
|
||||
class PluginHandle(private val manager: PluginManager, val name: String, val instance: Plugin, val config: JSObject) {
|
||||
private val commands: HashMap<String, CommandData> = HashMap()
|
||||
private val permissionCallbackMethods: HashMap<String, Method> = HashMap()
|
||||
private val startActivityCallbackMethods: HashMap<String, Method> = HashMap()
|
||||
|
@ -46,6 +46,12 @@ class PluginManager(val activity: AppCompatActivity) {
|
||||
}
|
||||
}
|
||||
|
||||
fun onNewIntent(intent: Intent) {
|
||||
for (plugin in plugins.values) {
|
||||
plugin.instance.onNewIntent(intent)
|
||||
}
|
||||
}
|
||||
|
||||
fun startActivityForResult(intent: Intent, callback: ActivityResultCallback) {
|
||||
startActivityForResultCallback = callback
|
||||
startActivityForResultLauncher.launch(intent)
|
||||
|
@ -1,7 +1,15 @@
|
||||
package {{reverse-domain app.domain}}.{{snake-case app.name}}
|
||||
|
||||
import android.os.Bundle
|
||||
import app.tauri.plugin.PluginManager
|
||||
|
||||
abstract class TauriActivity : WryActivity() {
|
||||
var pluginManager: PluginManager = PluginManager(this)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (intent != null) {
|
||||
pluginManager.onNewIntent(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user