Android O中的ACTION_MEDIA_MOUNTED广播

时间:2017-11-08 04:02:57

标签: android broadcastreceiver

下面的动态广播接收器测试并在Android工作室模拟器API 25(Android N)上工作但未能在API 26(Android O)上接收。

public class MainActivity extends AppCompatActivity {

    private BroadcastReceiver mReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Log.i(getClass().getName(),intent.getAction());
            }
        };

        IntentFilter intent = new IntentFilter();
        intent.addAction(Intent.ACTION_MEDIA_MOUNTED);
        intent.addAction(Intent.ACTION_MEDIA_EJECT);
        intent.addDataScheme("file");
        registerReceiver(mReceiver, intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mReceiver);
    }
}

有谁可以指出它有什么问题?

0 个答案:

没有答案