Manifest permission needed to copy files to the Android device internal area? - android

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

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.

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

Related

Rare Android Unable to Instantiate Application Exception

I'm seeing the following exception under Crashes in the dev console from time to time.
Whats puzzling about it is that google maps shows up in the call stack as if its calling or creating my app class - very confusing. Whats further weird is the "MyApp-2.apk" in the call stack - where it appends the "-2".
I do include the android.maps.jar file in the libs.
I would like to know how to recreate this if possible and how to prevent this from happening?
java.lang.RuntimeException: Unable to instantiate application com.MyApp.MyCustomApp:
java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp"
on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
at android.app.LoadedApk.makeApplication(LoadedApk.java:503)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4405)
at android.app.ActivityThread.access$1400(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5059)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp" on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:967)
at android.app.LoadedApk.makeApplication(LoadedApk.java:498)
... 11 more
Manifest Application Tag:
<application
android:name=".MyApp"
android:hardwareAccelerated="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
I'm using these JARS: android-support-v4-r2-googlemaps.jar + android-support-v4.jar
The prime reason why a Class within your application would be present on your test devices but missing at runtime on some others would be if your class has a dependency on some external feature which is missing on those devices. For example, if you used some Google API which is not part of AOSP and so missing on a plain AOSP build, or a vendor build which does not license these, then your class will be pruned at install time as its dependencies cannot be resolved.
A common reason for your app finding its way into such circumstances might be someone running an inconsistently assembled "custom ROM" on their device.

AnalyticsService: java.lang.SecurityException: attempting to read gservices without permission

I've spent the entire day attempting to fix this, please find the stack trace below, coming from the Google Play Services lib. I changed nothing, i rebuilt the app today and ever since have been given this error. I've tried upgrading GPS to the latest version, rebuilding GPS, downgrading GPS to a previous version, removing various other libraries, explicitly adding the permission it requests and other such niceties... but NOTHING.
if ANYONE can please lend some advice i'd be forever grateful.
java.lang.RuntimeException: Unable to instantiate service
com.google.android.gms.analytics.service.AnalyticsService: java.lang.SecurityException: attempting to
read gservices without permission: Neither user 10064 nor current process has
com.google.android.providers.gsf.permission.READ_GSERVICES. at
android.app.ActivityThread.handleCreateService(ActivityThread.java:1929) at
android.app.ActivityThread.access$2500(ActivityThread.java:117) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:985) at
android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at
android.app.ActivityThread.main(ActivityThread.java:3683) 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:895) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653) at dalvik.system.NativeStart.main(Native
Method) Caused by: java.lang.SecurityException: attempting to read gservices without permission:
Neither user 10064 nor current process has
com.google.android.providers.gsf.permission.READ_GSERVICES. at
android.app.ContextImpl.enforce(ContextImpl.java:1289) at
android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1318) at
android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:395) at
imq.c(SourceFile:107) at imq.a(SourceFile:121) at blw.a(SourceFile:276) at blu.b(SourceFile:203) at
blo.c(SourceFile:135) at com.google.android.gms.analytics.service.AnalyticsService.<init
(SourceFile:53) at java.lang.Class.newInstanceImpl(Native Method) at
java.lang.Class.newInstance(Class.java:1409) at
android.app.ActivityThread.handleCreateService(ActivityThread.java:1926) ... 10 more

Android Crash, java.lang.IllegalArgumentException: Window type can not be changed after the window is added

I uploaded an Android Application to the market, and, for some reason a user is getting this error.
java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
at android.os.Parcel.readException(Parcel.java:1331)
at android.os.Parcel.readException(Parcel.java:1281)
at android.view.IWindowSession$Stub$Proxy.relayout(IWindowSession.java:664)
at android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:3594)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1193)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2450)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4444)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
I am pretty sure I never use WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG as referenced in other postings. I do however, have a window that switches between WindowManager.LayoutParams.TYPE_PHONE and WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY. Which seems like it could be the error. I would prefer not changing this as it would require me to have two windows instead of just one. Thanks in advance!
check AndroidManifest.xml
<uses-sdk //************
android:targetSdkVersion="X"/>
X must be less than 14 Or remove this attribute.
good luck guy.

Android - Force close when no sd card is present

So I have an application which stores files in directories that I create when the user gets within a certain distance of a geographic location. Everything works fine except for when certain devices that usually use an sd card have it removed and then the app crashes when a user logs in. I tried on a droid x and I was able to replicate the crash. When I have the sd card in it works fine but when the sd card is removed I get a nullpointer exception and force close.
Heres the log dump from the market:
java.lang.RuntimeException: Unable to resume activity {graffit.cores/graffit.cores.GraffView}: java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2208)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2228)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1721)
at android.app.ActivityThread.access$1500(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
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)
Caused by: java.lang.NullPointerException
at graffit.cores.GraffView.onResume(GraffView.java:1201)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.Activity.performResume(Activity.java:3882)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2191)
... 12 more
java.lang.NullPointerException
at graffit.cores.GraffView.onResume(GraffView.java:1201)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.Activity.performResume(Activity.java:3882)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2191)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2228)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1721)
at android.app.ActivityThread.access$1500(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
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)
Being that the logdump says something about failing on instrumentation Im guessing that I should catch that or look for if an sd card is available.
Im sure I can find out how to look for an sd card but how can I catch this crash and use internal storage in place of a missing sd card.
Any help would be much appreciated.
Before you do any work with the external storage, you should always call getExternalStorageState() to check whether the media is available. The media might not always be available, such as in your case. The Android Docs give an example on how to deal with this: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
The best thing to do is probably do this check in a function that returns a Boolean value on whether you can get to the external storage and then check it each time you need to get data from the card.
if (sdCardAvalableForRead())
{
// get file.
}
else
{
// show warning or message to user.
}

Android intermittent class not found run time exception

One or two of my users experience the above class not found run time exception when trying to run my app.
How can that happen and how can I fix it? Is it a bad install?
Thanks
Paul
Stack trace received through Android Publishers site. I cannot replicate this myself.
(com.android.app.app.app) is the name of the app/activity as defined in the manifest.
java.lang.RuntimeException: Unable to
instantiate activity
ComponentInfo{my,app.app.app/com.android.app.app.app}:
java.lang.ClassNotFoundException:
com.android.app.app.app in loader
dalvik.system.PathClassLoader[/mnt/asec/my,app.app.app-1/pkg.apk]
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
at
android.app.ActivityThread.access$2500(ActivityThread.java:129)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
at
android.os.Handler.dispatchMessage(Handler.java:99)
at
android.os.Looper.loop(Looper.java:143)
at
android.app.ActivityThread.main(ActivityThread.java:4701)
at
java.lang.reflect.Method.invokeNative(Native
Method) at
java.lang.reflect.Method.invoke(Method.java:521)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at
dalvik.system.NativeStart.main(Native
Method) Caused by:
java.lang.ClassNotFoundException:
com.android.app.app.app in loader
dalvik.system.PathClassLoader[/mnt/asec/my,app.app.app-1/pkg.apk]
at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at
android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2651)
... 11 more
I'd check to see if these users are installing the app on an SD card: if the app is installed the app icon might be visible in the application list (since that is stored on-device) but if the SD card is unavailable (removed or maybe mounted for reading by a PC over USB) when the user taps the application icon the attempts to load will fail. You will notice:
ComponentInfo{my,app.app.app/com.android.app.app.app}: java.lang.ClassNotFoundException: com.android.app.app.app in loader dalvik.system.PathClassLoader[/mnt/asec/my,app.app.app-1/pkg.apk] at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659) at
in your stack trace above: is /mnt/asec the SD card storage path on the device?

Categories

Resources