Android `onNewIntent`
#4118
-
Hey, do anyone knows if it's possible to adapt this example to a Dioxus app ? |
Beta Was this translation helpful? Give feedback.
Answered by
Kbz-8
Jun 19, 2025
Replies: 2 comments
-
up ! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I've managed to do it. If anyone has this need one day here's how I did it Use a fork of dioxus to be able to override the package dev.dioxus.main;
import com.yes.app.BuildConfig;
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
typealias BuildConfig = BuildConfig;
class MainActivity : WryActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.data?.let { notifyOnNewIntent(it.toString()) }
}
companion object {
init {
System.loadLibrary("dioxusmain")
}
}
private external fun notifyOnNewIntent(data: String)
} and on the rust side implemented this #[allow(non_snake_case)]
#[unsafe(no_mangle)]
pub extern "C" fn Java_dev_dioxus_main_MainActivity_notifyOnNewIntent(
mut env: jni::JNIEnv,
_class: jni::objects::JClass,
data: jni::objects::JString,
) {
let string: String = match env.get_string(&data) {
Ok(s) => s.into(),
Err(e) => {
eprintln!("Failed to convert Java string: {:?}", e);
return;
}
};
} be careful as the rust function is called on the JVM thread and not the Dioxus thread |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kbz-8
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've managed to do it. If anyone has this need one day here's how I did it
Use a fork of dioxus to be able to override the
MainActivity.kt
file (this may be added to dioxus hopefully) and implemented it like so