我可以在Android中使用Java中的以下代码链接服务名称。
//packageToCheck - pass the package name
PackageInfo servicePackage = null;
servicePackage = pm.getPackageInfo(packageToCheck, PackageManager.GET_SERVICES);
ServiceInfo[] sinfo = servicePackage.services;
for(ServiceInfo Servinfo : sinfo){
System.out.println("Service Name:" + Servinfo.name + "for Package:" + packageToCheck);
}
现在,我正在尝试使用C代码在JNI中实现。关于如何实现这一点的任何见解或示例代码?感谢!!!
我的第一次尝试是:jclass cls =(* env) - > GetObjectClass(env,obj);
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "1\n");
jmethodID mid = (*env)->GetMethodID(env, cls, "getPackageManager", "()Landroid/content/pm/PackageManager;");
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "2\n");
jobject packageManager = (*env)->CallObjectMethod(env, obj, mid);
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "3\n");
// this.getPackageName()
mid = (*env)->GetMethodID(env, cls, "getPackageName", "()Ljava/lang/String;");
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "4\n");
jstring packageName = (jstring) (*env)->CallObjectMethod(env, obj, mid);
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "5\n");
输出“2”后挂在LogCat中。不确定有什么问题!!!