开发者

address path in android

I have a function in c++ and I want to call it it java for android. I write it and build its library but the problem is I can not find file in emulator. I use adb push text.txt sdcard to copy text.txt to sdcard of emulator. but I could not find the file with the C function.

I call Simple("hello");

This is my C file :

jint Java_X_XX_XXX_wipeActivity_Simple(JNIEnv* env, jobject javaThis,jstring jstr)
{
    jboolean iscopy;
    const char *address = (*env)->GetStringUTFChars(env, jstr, &iscopy);

    return replaceZero("/sdcard/text.txt");
    //remove(address);
}
jint replaceZero(const char *address)
{
    FILE *fp;
    fp = fopen(address,"r+");
    if(fp == 0)
    {
        printf("can not find!!");
        return -1;
    }
    else
    {
        //do sth with file
             return 0;
    }
}

and I will see -1 in 开发者_如何学Gomain program.


I found the answer - I needed to add this to manifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

I cannot open it without permission.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜