getExternalFilesDir() returns null (not a permissions issue) - android

I've been working on an app for some time, and have been testing it on many devices. Suddenly, it stopped working on the Motorola Xoom Family Edition (Honeycomb 3.1). Every time I would try to run the app, it would fail on the call to getExternalFilesDir(), as that call would return null instead of a File.
From my research, anyone with a similar problem is either missing the WRITE_EXTERNAL_STORAGE, never got an answer, or was talking about a bug in Froyo. None of that applies here--and again, it works fine on other devices, I have the WRITE_EXTERNAL_STORAGE permission, and it was even working on this device until a few minutes ago.
Any idea what might cause this issue, or how to programmatically prevent it?

The problem went away after I restarted the tablet. It may just be some bizarre quirk that is extremely rare and fixed by a simple restart; I hope not, as I would like to have a solid way to prevent this instead of just hoping that any users who run into the bug are understanding.

Same problem on Samsung SCH-1405 (VZW Galaxy II) running 2.3.6 (kernel 2.6.35.7-FF1). No problems getting the external files directory for months and then bam, it starts to return NULL. Restarted phone and problem went away. Not a good omen.
A possible cause could be that I've been switching this phone in and out of USB debugging mode to get screen shots and have been ripping out the USB cable from the phone without first unmounting the phone's file systems from my Mac. This is new behavior on my part.
When I look at the return result from android.os.Environment.getExternalStorageState() with the problem present I see "shared", but when the phone is restarted the result is "mounted". Thus it seems that when the phone thinks that the external storage is "shared" then it is not allowing an app to access the external storage. This is speculation.

This will happen if the device is in "Mass Storage" mode. If you change it to MTP or "Charge Only", depending on the device, it should work. This is because the external data storage is technically not mounted to the device but to your computer.

Related

Partitioning an SD card through ADB (Android Debugging Bridge)

I've been trying to do this for 3 days now but i can't seem to get this to work.
So the gist of it is, I have an LG G6 running Android 8.0, with a 128Gb micro-SD card, I'm running out of internal space, and apparently LG and Samsung remove the adoptable storage feature from their android versions, I found a turn around to this which was to use ADB to partition the SD drive myself, and getting it to behave as internal memory, at first I had an issue with ADB even noticing my device, which I fixed by enabling USB tethering.
Past that everything seems to be going well, do the partition and reboot my phone,(speaking of which SD card is only detected after a reboot if I physically eject it and put it back in) all looks fine as per the screenshots
https://imgur.com/a/G7OJjFJ
(I was told memory misrepresentation was normal) until I get to the migrate data option which ALWAYS crashes the settings app, on top of that when I plug my phone into my computer I can only see the default internal storage of my device without any added memory.
I've reached a dead end and would appreciate anything at this point, even alternatives if you'd recommend I do something else (rooting or other methods i don't know about). Below are the sources I followed for this process, thanks in advance and if I missed any info let me know.
https://www.xda-developers.com/install-adb-windows-macos-linux/
https://www.androidpit.com/how-to-format-microsd-cards-as-internal-storage?fbclid=IwAR1pgqf6Ti2rSf_hbiyqLl0HufPewlPCHYmfBcfEzq_XRMhKxevwwq_mk28
https://www.modaco.com/news/android/heres-how-to-configure-adoptable-storage-on-your-s7-s7-edge-r1632/
Commands i entered by order as requested:
adb shell
sm list-disks
sm partition disk:179,0 private
And yes 179,0 IS the disk name on my phone as far as i can tell
I think that after the sm partition disk there is one thing that you didnt do. That is, sm set-force-adoptable false
After this jsut restart your phone and its gonna work most prob.

Android Tablet is restarting by itself

I have a custom android tablet and we have created an application which is used for home automation.I have installed the application in it and it works fine. I got the comments from the client saying that the tablet restarts by itself at night. I tried to catch the log by connecting it to eclipse but it didnt happend here. Will the tablet restart by itself under any circumstances ? , The tablet is a samsung ARM with 512mb ram and 4gb sdcard in it which runs on android version 2.2.
You have not provided any code, which leads me to assume the following. Unless you have the permission of PowerManager, you app has no control over the device's off/on state.
You also mentioned, on testing, you were not able to pinpoint the issue that the client talked about. This is very important information, and it helps strengthen my conclusion. Again, if the above criterion is correct (you don't have powermanager) then, it could be the clients tablet is just messed up...
The reebooting is actually a common problem:
http://forums.androidcentral.com/samsung-galaxy-tab-pro-8-4/453390-why-my-tablet-randomly-rebooting-resetting.html
Here, user B. Diddy states:
It's hard to say. Random reboots can happen because of problems with
the firmware, but can also be due to some app you installed that is
making the system unstable, or perhaps some bad bit of data that is in
the system cache. A corrupt SD card can also cause problems. Here are
some things you can try:
Unmount your SD card in Settings>Storage, remove it, and reboot. Use the tablet for a while (like a few days) without the SD card and
see if the random reboots recur. If they don't, plug it back in again,
and see if the reboots start again.
Boot into Safe Mode, which temporarily disables all 3rd party apps: Safe mode: Samsung Galaxy Tab 4 | T-Mobile Support. (I couldn't find
steps specifically for the Tab Pro, so I'm assuming the steps for the
Tab 4 are the same.) This might not be an effective troubleshooting
method if the random reboots don't occur very often, because it's hard
to expect anyone to use their tablet for several days in Safe Mode,
thus being unable to access any of the 3rd party apps you installed.
Boot into Recovery Mode and wipe the cache partition, which doesn't erase any personal data. Follow the steps in this video, and make sure
you select Wipe Cache Partition, and not Wipe Data/Factory Reset.
So, let me know if your app uses the PowerManager permission. If it doesn't you're good to go, and it is probably a faulty tablet.
Ruchir

Device Administrator rights disabled on phone restart

I have created an android application with device admin rights. It was working properly on my Moto G and many other devices. In Sony Xperia C, the device administrator rights disabled automatically on phone restart. Is anyone come across such issue? and how to fix them?
There may be other ways of doing it, but what springs to mind is a startup script. There's an interesting article here on creating them, which you might use to automatically set admin permissions to your app.
My app had a similar problem on this phone and I think I've worked out what is happening.
If the user moves the app from internal memory to the SD card, the app can lose its Device Administrator privileges when the SD card is unmounted. This would likely happen when the phone is restarted.
According the Android documentation, if you don't specify an installLocation in the manifest, an app should not be moveable. I think some phones break this rule and allow an app to be moved anyway.

Android Device, Internal Disk Space runs out real quick

I'm having a problem with one of the applications I'm developing.
So far, I'm using USB Debugging mode to install/update the app in my Android device, that's a Huawei MediaPad 7 Lite (Android ICS 4.0.3).
The app is using (According to the Internal Storage in Applications menu) 4.91 MB.
We've been testing it, and the disk space is being consumed by a 1GB per week ratio... Waaaay too much space.
I've checked my application and couldn't find at first sight a memory leak. I've searched a lot, and in a very few places, I've seen that turning USB Debugging off helps.
My question is...
Can this be caused by logging or other functionality I don't know of in the "USB Debugging Mode", or is definitely a coding problem on my side?
Thanks a lot
The problem comes with the OS itself.
Android has the option to log all the GPS information, apparently, this is only enabled on some devices.
The solution is to disable this GPS log, the device needs to be rooted and you need to edit the file located in /system/etc/gps/glconfig.xml
Find the block
<hal
acPortName="/dev/ttyS3"
IBaudRate="115200"
cLogEnableInitState="true"
cLogEnabled="true"
acLogDirectory="/data/gps/log/"
acNmeaOutName="/data/gpspipe"
ctrlPipe="/data/gps/glgpsctrl"
acNvStoDir="/data/gps/"
ItoFileName="Ito2.dat"
/>
All we need to change is the line cLogEnabled="true", make it false, and that's it.

Android phone reboots on uninstall

I am developing an app and when I uninstall the phone kind of semi-reboots.
This is my old post:
I have a strange problem with my phone. I am using SAMSUNG GALAXY 5
(GT-I5500) with Android 2.2 on it (not rooted).
I am an android developer and I have been doing pretty advanced apps.
However, sometimes when I am testing and installing an application the
phone reboots.
I'm starting it trough Eclipse but I do not know what exactly what
causes the phone to reboot.
It is not heat for sure, as I keep my phone cool enough.
It is not from the app source itself as the phone doesn't reboot while I am using the application but on installing time
It is not storage I think, because I have 26 MB internal and 1GB external memory free and the app is no more than 2 MB.
So my question is what could cause the phone to reboot?
In this context I define "reboot" as the phone showing the initial SAMSUNG screen, like normal booting but without the prompt for PIN. This is why I conclude it is something like semi-reboot or I do not exactly know.
Having experienced the same problem, I found that deleting dalvik cache and formatting cache partition helped - I can't tell which one of those two did the trick, but I can now happily uninstall apps again, without the device spontaneously rebooting.
Both operations I was able to perform in recovery mode, using ClockWorkMod rescue system, and they are non-destructive. No actual data or apps are lost, only next reboot takes longer, due to dalvik cache being rebuilt.
Today, close to a month later, that problem showed again, so I was able to test which of those two action fixes it. Turns out it was erasing the cache. Dalvik cache was left alone, deletion was possible afterwars nevertheless.
I have this exact problem with my LG G4. Whenever I try to uninstall an app the phone will just reboot. Luckily there is a way to remove unwanted apps if your phone has an expandable memory option through micro SD. Just transfer the unwanted app on the SD card then remove the card. The app will no longer exist on your phone. You can then just delete the app from your SD card using a PC. This doesn't help resolve the actual OS issue on your device but at least it's a quick fix for anyone who's looking to free up some space. Hope it helps!
Spontaneous reboots under unclear conditions, one of the "fun" things you get for free with Android. Not on each and every device, OS version or combination thereof, but quite too often.
With the following instructions you will loose all your data on your phone.
Try this: Get into the recovery mode (adb reboot recovery or start the phone with pressing (and holding) volume down, then press and hold the center key, then power on), then wipe data/factory reset, wipe cache partition.
(I experienced similar reboots but not with an I5500, so I don't know if this will help in this situation. It helped with a Motorola Milestone/Droid after upgrading to Android 2.2.)
I was able to fix this problem by wiping the davilk-cache thanks to Deleted User's experience. However, wiping the cache partition was not necessary in my case. I'm rooted stock Android 4.4.2 KitKat on a Galaxy Tab 3 SM-T210R.

Categories

Resources