[英]Manifest permission needed to copy files to the Android device internal area?
I would like to give the user the choice to copy files onto the Android device data directory as well as the external area. 我想让用户选择将文件复制到Android设备数据目录以及外部区域。
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. 我计划将文件存储在/data/data/your.app.package.name/myFiles中。 In the code, File.DirInternal translates to that location.
在代码中,File.DirInternal转换为该位置。
If I use File.DirRootExternal, it goes to /mnt/sdcard which does not crash the app. 如果我使用File.DirRootExternal,它会转到/ mnt / sdcard,这不会导致应用程序崩溃。
That's why I thought the manifest was causing the issue. 这就是我认为清单导致问题的原因。
It crashes on this line if I use File.DirInternal: 如果我使用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
Take a look at Android's Data Storage doc for details on saving to internal storage. 有关保存到内部存储的详细信息,请查看Android的数据存储文档。
If you meant: 如果你的意思是:
/data/data/your.app.package.name/myFiles
/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
/数据/对myApp / MYFILES
Then the answer is that you can't without being rooted. 那么答案就是你不能没有扎根。 You don't have permissions to write to the /data folder.
您无权写入/ data文件夹。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.