我试图使用这种方法
context.getPackageManager().getInstallerPackageName(context.getPackageName());
在android JNI界面中。这就是我已经做过的事情,但我不知道如何继续:
// context
jclass native_context = env->GetObjectClass(thiz);
// context.getPackageManager()
jmethodID methodID_func = env->GetMethodID(native_context, "getPackageManager", "()Landroid/content/pm/PackageManager;");
jobject package_manager = env->CallObjectMethod(thiz,methodID_func);
jclass pm_clazz = env->GetObjectClass(package_manager);
//packageManager.getInstallerPackageName()
jmethodID methodId_pm = env->GetMethodID(pm_clazz,"getInstallerPackageName","(Ljava/lang/String)Landroid/content/pm/getInstallerPackageName;");
//context.getPackageName()
jmethodID methodID_packagename = env->GetMethodID(native_context,"getPackageName","()Ljava/lang/String;");
jstring name_str = static_cast<jstring>(env->CallObjectMethod(thiz,methodID_packagename));
jstring intaller = static_cast<jstring>(env->CallObjectMethod(package_manager,methodId_pm,name_str));
LOGD("%s", getCharFromString(env, intaller));`
Logcat错误:
06-04 18:18:41.445: A/art(28904): art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.NoSuchMethodError: no non-static method "Landroid/app/ApplicationPackageManager;.getInstallerPackageName(Ljava/lang/String)Landroid/content/pm/PackageManager/getInstallerPackageName;"
我的目标是在JNI界面中获取安装程序包名称并检查盗版应用程序(Java太弱)。
谢谢。
答案 0 :(得分:0)
getInstallerPackageName()获取一个String并返回一个字符串,因此该行应为:
jmethodID methodId_pm = env->GetMethodID(pm_clazz,"getInstallerPackageName","(Ljava/lang/String;)Ljava/lang/String;");