Play video after startup from sdcard
-
29-04-2021 - |
题
I have an app which is autostarting via BroadcastReceiver and is set as a homescreen on Android 2.3.3. API10 on an HTC Desire HD.
The app should play a video repeatedly right after starting, but as the sdcard is not ready it kills the application with a force close error message which doesn't go away.
At least I think it is because of the sdcard.
In the background, the homescreen restarts but the error message doesn't go away, it would be no problem if it would disappear a few seconds later, but it would be even greater if it wouldn't appear at all..
can you help me? thanks!
edit #1: this checks if the sdcard is ready. i only need read access..
static public boolean hasStorage(boolean requireWriteAccess) {
String state = Environment.getExternalStorageState();
Log.v("tomi", "storage state is " + state);
if (Environment.MEDIA_MOUNTED.equals(state)) {
if (requireWriteAccess) {
boolean writable = checkFsWritable();
Log.v("tomi", "storage writable is " + writable);
return writable;
} else {
return true;
}
} else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}
解决方案
do you have a solution for this?
First, you should not need both "autostarting via BroadcastReceiver" and "set as a homescreen". One should suffice, preferably the latter.
Once the activity launches, it can check Environment
to see if external storage is ready. If not, it can register a receiver for ACTION_MEDIA_MOUNTED
to find out when external storage becomes ready. Once it is ready -- and only at that point -- it can try to play the video.