清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
提供一个监听方法BroadcastReceiver 设置IntentFilter为:Intent.ACTION_MEDIA_MOUNTEDIntent.AC TION_MEDIA_EJECTIntent.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);//使用完注销广播监听函数