Android: How to broadcast intent from native code?

前端 未结 3 1285
别跟我提以往
别跟我提以往 2021-02-05 21:47

Is it possible to broadcast an Intent from native code? If so, is there documentation and/or sample code pertaining to the relevant APIs?

相关标签:
3条回答
  • 2021-02-05 22:07

    I think there is nothing complicated in broadcasting message from native code but only in case if the native function is called from Android Java application so you can pass a Context. As far as I know there is no such thing as Context for purely native applications therefore you can not broadcast an intent.

    0 讨论(0)
  • 2021-02-05 22:16

    Even a pure native application can broadcast an Intent. That means, even when native activity is the launcher, we can still broadcast Intents.

    0 讨论(0)
  • 2021-02-05 22:25

    You will need to call it by calling the Java API function - there is no JNI interface for intents.

    First look up the class for Intent, then look up the methods for constructing intents and broadcasting them, and call them.

    EDIT: Here is an incomplete example. jniEnv is passed into all your JNI functions.

    jclass activityClass = jniEnv->FindClass("android/app/Activity");
    jmethodID startAcitivtyMethod = jniEnv->GetMethodID(activityClass , "startActivity", "(Landroid/content/Intent;)V");
    jniEnv->CallVoidMethod(yourActivityObject, startAcitivityMethod, yourIntentObject);
    
    0 讨论(0)
提交回复
热议问题