JNI实现Broadcast-创新互联-成都快上网建站

JNI实现Broadcast-创新互联

JNIEXPORT jint JNICALL Java_com_encrypt_EncryptActivity_cputExtra(JNIEnv *env,

10余年的湖口网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销的优势是能够根据用户设备显示端的尺寸不同,自动调整湖口建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“湖口网站设计”,“湖口网站推广”以来,每个客户项目都认真落实执行。

        jobject, jobject mContext, jstring actionName, jobjectArray key,

        jobjectArray value) {

    //找到Intent类

    jclass intentClass = env->FindClass("android/content/Intent");

    if (intentClass == 0) {

        return 0;

    }

    jobject intent;

    jmethodID intentId;

    intentId = env->GetMethodID(intentClass, "", "()V");

    if (intentId) {

        intent = env->NewObject(intentClass, intentId);

    } else {

        return 0;

    }

    jmethodID setActionId = env->GetMethodID(intentClass, "setAction",

            "(Ljava/lang/String;)Landroid/content/Intent;");

    if (setActionId == 0) {

        return 0;

    }

    env->CallObjectMethod(intent, setActionId, actionName);

    jmethodID putExtraId = env->GetMethodID(intentClass, "putExtra",

            "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;");

    if (putExtraId == 0) {

        return 0;

    }

    int size = env->GetArrayLength(key);

    int i = 0;

    for (i = 0; i < size; i++) {

        jstring keys = (jstring) env->GetObjectArrayElement(key, i);

        jstring values = (jstring) env->GetObjectArrayElement(value, i);

        env->CallObjectMethod(intent, putExtraId, keys, values);

    }

    if (mContext == 0) {

        return 0;

    }

    jclass cls_context = env->FindClass("android/content/Context");

    if (cls_context == 0) {

        return 0;

    }

    jmethodID sendBroadcastId = env->GetMethodID(cls_context, "sendBroadcast",

            "(Landroid/content/Intent;)V");

    if (sendBroadcastId == 0) {

        return 0;

    }

    env->CallVoidMethod(mContext, sendBroadcastId, intent);

    return 1;

}

申明:

public native static int cputExtra(Context mContext,

      String action, String[] key, String[] value);

加载库:

  static {

    System.loadLibrary("****");

  }

调用:

 String[] a = {"a","b"};

 String[] c = {"c","d"};

 cputExtra(this,"android.provider.telephony.SMS_RECEIVED", a, c);

接收端:

public class sendBroadcasttest extends BroadcastReceiver {

  @Override

  public void onReceive(Context context, Intent intent) {

    // TODO Auto-generated method stub

    String str = intent.getAction();

    String name = intent.getStringExtra("b");

    Log.i("aaaaa", "FirstReceiver: " + name);

  }

}

  

    

      

        

        

      

    

需要添加权限

Broadcast使用可参考
http://192.210.60.138/dz/forum.php?mod=viewthread&tid=10&fromuid=1
(出处: IStudy)

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享名称:JNI实现Broadcast-创新互联
标题路径:http://kswjz.com/article/dsjdsc.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流