English 中文(简体)
利用C++和土著活动类别掌握安乐团的名称
原标题:Obtaining the name of an Android APK using C++ and the NativeActivity class

I m 采用NDK和原住民活动制书写一个灯。 我的估算取决于作为资产运输的第三方代码的几个参数。 目前,Im公司正在设法提取这些资产,同时保持双倍结构不变。

我先尝试使用资产管理,但为了像我刚才提到的那样开展一项简单的工作,似乎需要大量的编码。 我从那时起就把重点转向试图把APK作为ZIP的档案,并从中提取其内容。 但是,这要求我找到通往APK的确切道路。

在通常的安乐器中,人们会使用先令疗法,但这是一种附属于背景类别的抽象方法。 我的问题是,在不使用正常活动的情况下,我如何获得通往科索沃武装部队的确切道路?

此外,我还试图通过民族阵线打电话,但由于无法找到这种方法,这架直升机坠毁。

EDIT: Is this even possible?

最佳回答

我实际上能够通过荷兰广播公司打电话getPackageCodePath,并能够工作。 The following Code set at the first of android_main in the home-active model in NDK r7logs the right path and don tock:

void android_main(struct android_app* state) {
    struct engine engine;

    ANativeActivity* activity = state->activity;
    JNIEnv* env = activity->env;

    jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
    jmethodID methodID = (*env)->GetMethodID(env, clazz, "getPackageCodePath", "()Ljava/lang/String;");
    jobject result = (*env)->CallObjectMethod(env, activity->clazz, methodID);

    const char* str;
    jboolean isCopy;
    str = (*env)->GetStringUTFChars(env, (jstring)result, &isCopy);
    LOGI("Looked up package code path: %s", str);

    ...
}

但我觉得这样可能不是一个伟大的解决办法。 对我有两点担忧:

  1. Thread safety - there s an ugly warning about only using the env member of ANativeActivity in the main Java thread, and if I understand things correctly, this code is going to get run in the native activity s thread.
  2. ANativeActivity s clazz member appears to be misnamed and is actually the instance of the Java NativeActivity instead of the class object. Otherwise this code wouldn t work. I really hate relying on something that is obviously misnamed like this.

除此之外,它还发挥作用,而且我实际上打算利用它自己,利用校准和数据目录将资产从原木中提取。

问题回答

Since I just had to search for exactly how to do the attach/detach calls I ll paste the updated version here.

The following seems to get the right location without crashing (after minimal testing)

    ANativeActivity* activity = state->activity;
    JNIEnv* env=0;

    (*activity->vm)->AttachCurrentThread(activity->vm, &env, 0);

    jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
    jmethodID methodID = (*env)->GetMethodID(env, clazz, "getPackageCodePath", "()Ljava/lang/String;");
    jobject result = (*env)->CallObjectMethod(env, activity->clazz, methodID);

    const char* str;
    jboolean isCopy;
    str = (*env)->GetStringUTFChars(env, (jstring)result, &isCopy);
    LOGI("Looked up package code path: %s", str);

    (*activity->vm)->DetachCurrentThread(activity->vm);

能够在2014年修改。

ANativeActivity* activity = state->activity;
JNIEnv* env=0;

activity->vm->AttachCurrentThread(&env, NULL);

jclass clazz = env->GetObjectClass(activity->clazz);
jmethodID methodID = env->GetMethodID(clazz, "getPackageCodePath", "()Ljava/lang/String;");
jobject result = env->CallObjectMethod(activity->clazz, methodID);

jboolean isCopy;
std::string res = env->GetStringUTFChars((jstring)result, &isCopy);
LOG_DEBUG("Looked up package code path: %s", res.c_str());

activity->vm->DetachCurrentThread();

Did you try to read /proc/self/cmdline from your application? You should be able to open it as a normal (as far as proc files are normal :-) so you can read from the file until EOF, but not seek) c FILE and read from it.

作为电话机的一个实例,我可以从 p中看到,申请名称是预期的用名称:

 # ps | grep phone 
 radio     1588  839   1467420 103740 SyS_epoll_ 7f7de374ac S com.android.phone

And checking the cmdline for that pid returns a good app name:

 # cat /proc/1588/cmdline
 com.android.phone

电话:getPackageCodePath() a. 本土方法





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签