JNI实现Broadcast
JNIEXPORT jint JNICALL Java_com_encrypt_EncryptActivity_cputExtra(JNIEnv *env,
10年积累的成都网站制作、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有新县免费网站建设让你可以放心的选择与我们合作。
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, "
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)
网页标题:JNI实现Broadcast
网址分享:http://cdiso.cn/article/jhpesg.html