zoukankan      html  css  js  c++  java
  • Android 监听外部U盘插入事件

    1、在AndroidManifest.xml 加入读取外部存储器权限

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    2、注册动态广播

    public static void register(Context context){
            IntentFilter filter = null;
            filter = new IntentFilter();
            filter.addAction(Intent.ACTION_MEDIA_MOUNTED);   //接收U盘挂载广播
            filter.addAction(Intent.ACTION_MEDIA_REMOVED);   //接收U盘卸载广播
            filter.addDataScheme("file");
            context.registerReceiver(mSdcardReceiver, filter,"android.permission.READ_EXTERNAL_STORAGE",null);
    
        }
    
        static BroadcastReceiver mSdcardReceiver = new BroadcastReceiver(){
    
            @Override
            public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub
                if(intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)){
                    Toast.makeText(context, "path:"+intent.getData().getPath(), Toast.LENGTH_SHORT).show();
                }else if(intent.getAction().equals(Intent.ACTION_MEDIA_REMOVED)){
                    Log.i("ants", "remove ACTION_MEDIA_REMOVED");
                }
            }
    
        };
  • 相关阅读:
    mysql索引
    mysql锁机制
    mysql授权
    mysql执行计划
    mysql知识补遗
    求助:springboot调用存储过程并使用了pagehelper分页时报错com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
    java面试题1
    Yarn
    MapRudecer
    Hive数据倾斜和解决办法
  • 原文地址:https://www.cnblogs.com/huhe/p/15353606.html
Copyright © 2011-2022 走看看