App Install Location Broadcast Receivers listening for "boot completed" The system delivers the ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast. http://www.ideasandroid.com/android/sdk/docs/guide/appendix/install-location.html android明确说明了,安装在sd卡上的应用程序是接收不到ACTION_BOOT_COMPLETED消息的,在mount sd卡之前这个消息已经发出了。
只要程序中注册android.intent.action.BOOT_COMPLETED到系统,就能实现开机启动啊可能是其它方面的问题吧看看程序有没有访问SDcard的权限等等其它的问题楼主再看看吧!
{
/*SD卡可用 正常操作*/
}else {
/*SD不可用 延时重新检查SD卡可不可用 重复几次 直到SD卡可用 */;
}
即提供一个监听方法BroadcastReceiver 设置IntentFilter为:
Intent.ACTION_MEDIA_MOUNTED
Intent.ACTION_MEDIA_EJECT
Intent.ACTION_MEDIA_REMOVED
然后再public void onReceive(Context context, Intent intent) 中实现你的启动逻辑startActivity网上别人的代码,参考:
private final BroadcastReceiver broadcastRec = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equals("android.intent.action.MEDIA_MOUNTED"))//SD 卡已经成功挂载 { imagepath = android.os.Environment.getExternalStorageDirectory();//你的SD卡路径 }else if(intent.getAction().equals("android.intent.action.MEDIA_REMOVED")//各种未挂载状态 ||intent.getAction().equals("android.intent.action.ACTION_MEDIA_UNMOUNTED") ||intent.getAction().equals("android.intent.action.ACTION_MEDIA_BAD_REMOVAL")) { imagepath = android.os.Environment.getDataDirectory();//你的本地路径 } } }; //在IntentFilter中选择你要监听的行为 IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED); intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); intentFilter.addAction(Intent.ACTION_MEDIA_REMOVED); //intentFilter.addAction(Intent.ACTION_MEDIA_SHARED); intentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL); //intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); //intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); intentFilter.addDataScheme("file"); registerReceiver(broadcastRec, intentFilter);//注册监听函数 unregisterReceiver(broadcastRec);//使用完注销广播监听函数
一种方式 直接用91安装到sd卡上
另一种方式 可以用系统的移至sd卡
Broadcast Receivers listening for "boot completed"
The system delivers the ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast.
http://www.ideasandroid.com/android/sdk/docs/guide/appendix/install-location.html
android明确说明了,安装在sd卡上的应用程序是接收不到ACTION_BOOT_COMPLETED消息的,在mount sd卡之前这个消息已经发出了。
你根本就没有理解楼主的意思,和sd卡有没有挂载有什么关系。应用装在外置sd中是无法收到那个广播的。