Android app开机广播开启app来电广播

来电广播检测,是否为本公司员工,是本公司员工,提示为本公司谁谁谁,哪个部门。
为了开机不启动app 也可以检测来电广播:

1、在静态注册广播的时候 指定exported = true

 <!-- 注册监听手机状态 -->
        <receiver
            android:name=".receiver.PhoneStateReceiver"
            android:exported="true">
            <intent-filter android:priority="1000">
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>

2.开机注册的广播

  <receiver android:name=".receiver.ContentReceiver">
            <intent-filter android:priority="1000">
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </receiver>

3,开机广播开启APP的手机状态广播


        Intent intent1 = new Intent();
        intent1.setAction("android.intent.action.PHONE_STATE");
        intent1.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
        context.sendBroadcast(intent1);

intent1.setAction(“android.intent.action.PHONE_STATE”); 这个是 2 中的

intent1.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);表示“Intent.FLAG_INCLUDE_STOPPED_PACKAGES”包含未启动的App

发布了46 篇原创文章 · 获赞 21 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/u012922981/article/details/82698647