概述
感謝 @PravinCG
下面是完整的代碼。
SDCardBroadcastReceiver.java 代碼public class SDCardBroadcastReceiver extends BroadcastReceiver {
private static final String ACTION_MEDIA_REMOVED ="android.intent.action.MEDIA_REMOVED";
private static final String ACTION_MEDIA_MOUNTED ="android.intent.action.MEDIA_MOUNTED";
private static final String MEDIA_BAD_REMOVAL ="android.intent.action.MEDIA_BAD_REMOVAL";
private static final String MEDIA_EJECT ="android.intent.action.MEDIA_EJECT";
private static final String TAG ="SDCardBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG,"Intent recieved:" + intent.getAction());
if (intent.getAction() == ACTION_MEDIA_REMOVED) {
Log.e(TAG,"ACTION_MEDIA_REMOVED called");
//For bundle Extras do like below
//Bundle bundle = intent.getExtras();
//if (bundle!= null) {
//
//}
}else if (intent.getAction() == ACTION_MEDIA_MOUNTED){
Log.e(TAG,"ACTION_MEDIA_MOUNTED called");
}else if(intent.getAction() == MEDIA_BAD_REMOVAL){
Log.e(TAG,"MEDIA_BAD_REMOVAL called");
}else if (intent.getAction() == MEDIA_EJECT){
Log.e(TAG,"MEDIA_EJECT called");
}
}
}
這是我的manifest.xml 文件<?xml version="1.0" encoding="utf-8"?>
package="genetechsolutions.sdcardmountlistner">
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
最后
以上就是傻傻跳跳糖为你收集整理的android+监控+sd+usb+移除,android: 如何监听sd被意外移除 removed"_android_开发99编程知识库...的全部内容,希望文章能够帮你解决android+监控+sd+usb+移除,android: 如何监听sd被意外移除 removed"_android_开发99编程知识库...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复