zoukankan      html  css  js  c++  java
  • 关于监听系统开机广播的权限问题

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.broadcastofboot">
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <receiver
                android:name=".BootCompleteReceiver"
                android:enabled="true"
                android:exported="true">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>
                </intent-filter>
            </receiver>
        </application>
    
    </manifest>
    

    然而,开机并不能接受到广播。

    后来在网上查看问题所在,找到答案。

    如果是三方应用没有系统权限的话,无解。
    原因如下:
    谷歌为了安全考虑(避免流氓软件、病毒啊干坏事,还能提高效率),4.0以后加了2个Flag:FLAG_INCLUDE_STOPPED_PACKAGES和FLAG_EXCLUDE_STOPPED_PACKAGES。系统发出的广播带有FLAG_EXCLUDE_STOPPED_PACKAGES这个flag,在应用进程没有启动的情况下是不能接收到的。
    当然如果是用户自定义的广播可以带有FLAG_INCLUDE_STOPPED_PACKAGES这个flag,那么即使应用没启动也可以收到广播(很遗憾啊!只能是三方自定义的广播)。

    链接:http://bbs.csdn.net/topics/390630274/

  • 相关阅读:
    【原】基础篇:第九篇,Ext组件系列之field组件的基本用法
    为什么要返回byte[]
    Migrate Mysql to SQL Server 2005
    关于编码规范
    RPM删除包的时候报127错误
    邮政储蓄的线上故障
    string.replaceAll与StringUtils.replace
    EJB工作原理
    OJB Connection
    找工作
  • 原文地址:https://www.cnblogs.com/ProtectedDream/p/6160345.html
Copyright © 2011-2022 走看看