启动后从SD卡播放视频
我有一个通过 BroadcastReceiver 自动启动的应用程序,并在 Android 2.3.3 上设置为主屏幕。 HTC Desire HD 上的 API10。
应用程序应在启动后立即重复播放视频,但由于 SD 卡尚未准备好,它会终止应用程序并显示强制关闭错误消息,该消息不会消失。
至少我认为这是因为sdcard。
在后台,主屏幕重新启动,但错误消息并没有消失,如果几秒钟后消失也没有问题,但如果根本不出现那就更严重了..
你能帮忙吗我? 谢谢!
编辑#1: 这将检查 SD 卡是否准备就绪。我只需要读取权限..
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您不需要“通过 BroadcastReceiver 自动启动”和“设置为主屏幕”。一个就足够了,最好是后者。
活动启动后,它可以检查
Environment
以查看外部存储是否准备就绪。如果没有,它可以为ACTION_MEDIA_MOUNTED
注册一个接收器,以了解外部存储何时准备就绪。一旦准备好——并且只有在那时——它就可以尝试播放视频。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 forACTION_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.