广播动态注册

1.发广播

 Intent intent = new Intent("android.intent.action.glovemode");
	       mContext.sendBroadcast(intent);

2.注册

      IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.glovemode");
        getActivity().registerReceiver(receiver,intentFilter);
 private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
		     Log.e("yanghonglog","Glove----onReceive");
        boolean touchScreenSensitivityEnabled2 = Settings.Secure.getInt(getContentResolver(),
                Settings.Secure.TOUCH_SCREEN_SENSITIVITY, 0) != 0;
        mTouchScreenSensitivityPreference.setChecked(touchScreenSensitivityEnabled2);
		
        }
    };

3.取消注册

getActivity().unregisterReceiver(receiver);
发布了56 篇原创文章 · 获赞 14 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览