安卓SD卡就绪的Intent

18
我有一个应用程序使用SD卡上的文件,当手机启动时运行该应用程序,但显然当程序在SD卡可用之前开始工作时,该文件无法访问。

是否有广播接收器可以用来告诉我何时SD卡已准备好?

更新

注册Intent的答案总结如下:

IntentFilter filter = new IntentFilter (Intent.ACTION_MEDIA_MOUNTED); 
filter.addDataScheme("file"); 
registerReceiver(this.mSDInfoReceiver, new IntentFilter(filter));

并创建一个广播接收器以对其进行响应:

private BroadcastReceiver mSDInfoReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg0, Intent intent) {
    // Code to react to SD mounted goes here
    }
 }; 
1个回答

18

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"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接