广播接收器在设备重启时取消注册。

huangapple 未分类评论43阅读模式
英文:

broadcast receiver gets unregistered on device reboot

问题

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package=""
    android:installLocation="internalOnly">
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true">

        <receiver
            android:name=".NotifReceiver"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

        <activity
            android:name=".MainActivity"
            android:label=""
            android:theme="@style/AppTheme">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME" />
                <action android:name="android.intent.action.MAIN"/>
            </intent-filter>
        </activity>

    </application>
</manifest>

I have a broadcast receiver that should be triggered when the device is booted, but it never gets triggered when the device is booted. Instead, the whole broadcast receiver gets unregistered. I know this issue has been asked about multiple times before, but none of the solutions seem to work.

Thanks in advance.

Edit: I am using API 19.

英文:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
package=&quot;&quot; android:installLocation=&quot;internalOnly&quot;&gt;
&lt;uses-permission android:name=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot; /&gt;
&lt;application
    android:allowBackup=&quot;true&quot;
    android:icon=&quot;@mipmap/ic_launcher&quot;
    android:label=&quot;@string/app_name&quot;
    android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
    android:supportsRtl=&quot;true&quot;
    &gt;

    &lt;receiver
        android:name=&quot;.NotifReceiver&quot;
        android:enabled=&quot;true&quot;
        android:exported=&quot;true&quot;
        android:permission=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot;&gt;
        &lt;intent-filter&gt;
            &lt;action android:name=&quot;android.intent.action.BOOT_COMPLETED&quot;/&gt;
        &lt;/intent-filter&gt;

    &lt;/receiver&gt;
  
    &lt;activity
        android:name=&quot;.MainActivity&quot;
        android:label=&quot;&quot; android:theme=&quot;@style/AppTheme&quot;&gt;
        &lt;intent-filter&gt;
            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;category android:name=&quot;android.intent.category.HOME&quot; /&gt;
            &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;

        &lt;/intent-filter&gt;
        
    &lt;/activity&gt;



&lt;/application&gt;

</manifest>

i have a broadcast receiver which should be triggered when device is booted but it never gets triggered
when device is booted instead the whole broadcast receiver gets unregistered
.i know this has been asked multiple times before but none of the solutions seem to work

thanks in advance

edit : i am using api 19

答案1

得分: 0

Remove android:permission="android.permission.RECEIVE_BOOT_COMPLETED" from your <receiver> element.

英文:

Remove android:permission=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot; from your &lt;receiver&gt; element.

huangapple
  • 本文由 发表于 2020年7月27日 07:18:38
  • 转载请务必保留本文链接:https://java.coder-hub.com/63106781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定