【问题标题】:RECEIVE_BOOT_COMPLETED is not working in Lollipop deviceRECEIVE_BOOT_COMPLETED 在棒棒糖设备中不起作用
【发布时间】:2016-01-20 01:52:08
【问题描述】:

我试图在我的应用程序中实现一个可以在启动时工作的接收器。为此,我创建了一个 MyReceiver 类,然后将其添加到我的清单中。我也添加了权限。但它不起作用,也没有显示在应用信息中。

这是我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.inapp.sampleboot" >

    <uses-permission android:name="ANDROID.PERMISSION.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".MyReceiver"
            >
            <intent-filter>
                <action android:name="ANDROID.INTENT.ACTION.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

我的接收者班级

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

    }
}

【问题讨论】:

  • 粘贴你的接收器类

标签: android android-permissions user-permissions bootcompleted


【解决方案1】:

安装后至少启动一次您的应用程序,然后重新启动您的设备。希望它会工作

【讨论】:

    【解决方案2】:

    您的接收者意图过滤器中有两个操作。那就是问题所在。而是为接收者设置两个意图过滤器。

    可能是这样的:

    <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
    <intent-filter>
                    <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
    </intent-filter>
    

    你真的需要第二个动作吗?

    如果您遇到关于此主题的任何其他问题,请查看此内容:https://stackoverflow.com/a/26026471/4747587

    【讨论】:

      【解决方案3】:

      我认为这将是一个解决方案

      <uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE" />
      

      Android 在大多数地方都区分大小写。请将其更改为:

      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
      

      【讨论】:

        猜你喜欢
        • 2017-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-07
        • 1970-01-01
        • 1970-01-01
        • 2015-01-12
        • 1970-01-01
        相关资源
        最近更新 更多