JNI项目的PackageManager $ NameNotFoundException

时间:2016-10-14 08:55:08

标签: android android-ndk

获取PackageManager $ NameNotFoundException以获取android studio中的签名捕获代码

->find

jni.c

package com.example.u29692.helloandroidjni;
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
   ((TextView) findViewById(R.id.jni_msgView)).setText(stringFromJNI(this));
}
// new code
static {
    System.loadLibrary("hello-android-jni");
}
// public native String getMsgFromJni();
public native String stringFromJNI(Context context);

应用程序崩溃了日志:

#include <jni.h>

JNIEXPORT jstring JNICALL
Java_com_example_u29692_helloandroidjni_MainActivity_stringFromJNI(JNIEnv *env, jobject instance,
                                                               jobject context) {

    // TODO

    // For class Context
    jclass native_clazz = (*env)->GetObjectClass(env, context);

    // Get the getPackageManager method ID
    jmethodID methodID_func = (*env)->GetMethodID(env, native_clazz,
                                              "getPackageManager", "()Landroid/content/pm/PackageManager;");

    // Access manager application package
    jobject package_manager = (*env)->CallObjectMethod(env, context, methodID_func);

    // For class PackageManager
    jclass pm_clazz = (*env)->GetObjectClass(env, package_manager);

    // Get the getPackageInfo method ID
    jmethodID methodID_pm = (*env)->GetMethodID(env, pm_clazz,
                                            "getPackageInfo", "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;");

    // To obtain the application package information
    jobject package_info = (*env)->CallObjectMethod(env, package_manager,
                                                methodID_pm, (*env)->NewStringUTF(env, "com.example.u29692.helloandroidjni"), 64);
    return (*env)->NewStringUTF(env, package_info);
}

0 个答案:

没有答案