Question

I would like to give the user the choice to copy files onto the Android device data directory as well as the external area.

Can you tell me what I need to add to the manifest that will allow my app to copy the files to the internal area?

I was planning on storing the files in /data/data/your.app.package.name/myFiles. In the code, File.DirInternal translates to that location.

If I use File.DirRootExternal, it goes to /mnt/sdcard which does not crash the app.

That's why I thought the manifest was causing the issue.

It crashes on this line if I use File.DirInternal:

mpTheMediaPlayer.Load(File.DirInternal, "114.mp3")

This is the code that's crashing:

' Http sub routines.
'-------------------
Sub JobDone(Job As String)

Select Job
    Case "Job1"

        If HttpUtils.IsSuccess(mp3Url) Then 
            Dim blnFolderMade As Boolean

            mp3 = HttpUtils.GetInputStream(mp3Url)

            timer1.Enabled = True

            Dim out As OutputStream
            out = File.OpenOutput(File.DirInternal,"114.mp3",False)
            File.Copy2(mp3, out)
            out.Close

            ProgressBarDownloading.Visible = False

            ToggleButtonPlayPause.Checked = True
            ToggleButtonPlayPause.Enabled = True
            blnCurrentPauseCheckedState = True
            blnCurrentPauseEnabledState = True

            mpTheMediaPlayer.Release
            mpTheMediaPlayer.Initialize2("")
            mpTheMediaPlayer.Load(File.DirInternal, "114.mp3")
            mpTheMediaPlayer.Play
        End If
End Select
End Sub

Here is the error from the logs:

Starting Job: Job1
** Service (httputilsservice) Create **
** Service (httputilsservice) Start **
main_jobdone (java line: 518)
java.io.IOException: Prepare failed.: status=0x1
at android.media.MediaPlayer.prepare(Native Method)
at anywheresoftware.b4a.objects.MediaPlayerWrapper.Load(MediaPlayerWrapper.java:79)
at quran.repeater.main._jobdone(main.java:518)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:97)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:772)
at anywheresoftware.b4a.keywords.Common.CallSub2(Common.java:759)
at quran.repeater.httputilsservice._processnexttask(httputilsservice.java:180)
at quran.repeater.httputilsservice._response_streamfinish(httputilsservice.java:244)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at anywheresoftware.b4a.BA$1.run(BA.java:218)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
java.io.IOException: Prepare failed.: status=0x1
Was it helpful?

Solution

Take a look at Android's Data Storage doc for details on saving to internal storage.

If you meant:

/data/data/your.app.package.name/myFiles

Then you don't need extra permissions. That's just regular writing to internal storage

If you meant external storage (which it sure doesn't look like) then you need

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

If you truly meant

/data/myApp/myFiles

Then the answer is that you can't without being rooted. You don't have permissions to write to the /data folder.

OTHER TIPS

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top