Announcement

Collapse
No announcement yet.

accessing file from sdcard???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    accessing file from sdcard???

    whole day i was trying to get access of a file "t.txt" that i had put in my sdcard:


    Code:
    FString InPath="/mnt/sdcard/t.txt";
    FString InPath="/sdcard/t.txt";
    FString InPath="./t.txt";
    
    FPaths::FileExists(InPath)
    then i tried to check its existence with FPaths::FileExists(InPath).
    but it always was returning false.

    what InPath value I should have use to get proper address?

    note:
    i also have added read permission under:
    project settings->android->extra permissions:
    android.permission.WRITE_EXTERNAL_STORAGE
    android.permission.READ_EXTERNAL_STORAGE
    UpWork Portfolio
    UE4 Portfolio

    Skype:
    muzahred57

    #2
    i figured out that i have to use something like this:


    FString myfile= GFilePathBase + FString(TEXT("/t.txt") ;



    GFilePathBase defination can be found in "Runtime\Launch\Private\Android\AndroidJNI.cpp"

    // Cache path to external storage
    jclass EnvClass = Env->FindClass("android/os/Environment");
    jmethodID getExternalStorageDir = Env->GetStaticMethodID(EnvClass, "getExternalStorageDirectory", "()Ljava/io/File;");
    jobject externalStoragePath = Env->CallStaticObjectMethod(EnvClass, getExternalStorageDir, nullptr);
    jmethodID getFilePath = Env->GetMethodID(Env->FindClass("java/io/File"), "getPath", "()Ljava/lang/String;");
    jstring pathString = (jstring)Env->CallObjectMethod(externalStoragePath, getFilePath, nullptr);
    const char *nativePathString = Env->GetStringUTFChars(pathString, 0);
    // Copy that somewhere safe
    GFilePathBase = FString(nativePathString);



    but problem is how to access "GFilePathBase ";?
    UpWork Portfolio
    UE4 Portfolio

    Skype:
    muzahred57

    Comment


      #3
      can somebody from epic's android department answer how to get the correct path for c++ as string?
      there should be simple a simple answer of this.
      the whole process is now pending because of this silly issue.
      UpWork Portfolio
      UE4 Portfolio

      Skype:
      muzahred57

      Comment


        #4
        You can access GFilePathBase by adding an extern FString GFilePathBase; if you know you are on Android (use #if PLATFORM_ANDROID / #endif around the code that uses it).

        Comment

        Working...
        X