Android 存储挂载监听 U盘挂载监听


xml 清单文件中的配置方式



                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                
        

USBReceiver 是你的广播接收者 BroadcastReceiver


动态注册方式方式


    private void registReceiver() {

        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(Intent.ACTION_MEDIA_EJECT);
        iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        iFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
        iFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        iFilter.addDataScheme("file");
        mBroadcastReceiver = new BroadcastRecevicer();
        registerReceiver(mBroadcastReceiver, iFilter);

    }






你可能感兴趣的:(Android开发)