我有一个使用 SD 卡上的文件的应用程序,该应用程序在手机启动时运行,并且很明显,当程序第一次运行时无法访问该文件,因为它在 SD 卡可用之前就开始工作.
我可以使用广播接收器来判断 SD 卡何时准备就绪?
更新
只是总结一下注册 Intent 的答案:
IntentFilter filter = new IntentFilter (Intent.ACTION_MEDIA_MOUNTED);
filter.addDataScheme("file");
registerReceiver(this.mSDInfoReceiver, new IntentFilter(filter));
并创建一个广播接收器对其使用react:
private BroadcastReceiver mSDInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent) {
// Code to react to SD mounted goes here
}
};
最佳答案
在 Intent 上查找 ACTION_MEDIA_MOUNTED
广播操作
public static final String ACTION_MEDIA_MOUNTED
Since: API Level 1
Broadcast Action: External media is present and mounted at its mount point. The path to the mount point for the removed media is contained in the Intent.mData field. The Intent contains an extra with name "read-only" and Boolean value to indicate if the media was mounted read only.
Constant Value: "android.intent.action.MEDIA_MOUNTED"
关于sdcard的android Intent 准备好了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3417161/