【问题标题】:BOOT_COMPLETED broadcast not received even after manually started app即使在手动启动应用程序后也未收到 BOOT_COMPLETED 广播
【发布时间】:2017-12-28 02:33:55
【问题描述】:

我想在设备启动时启动应用程序,但它不起作用,即使我添加了权限、意图过滤器和类别。

我知道在android 3.1之后,用户手动启动应用程序之前无法通过广播启动它。

所以我在安装后运行了几次应用程序,但它仍然无法运行。

下面是我的代码。

清单:

 <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"
    android:theme="@style/AppTheme">

    <receiver
        android:name=".Receiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />

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

和广播接收器类。

public class Receiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    String action = "action : " + intent.getAction();
    Log.d("MyTag", action);
    Toast.makeText(context, action, Toast.LENGTH_SHORT).show();
    context.startActivity(new Intent(context, MainActivity.class));
}
}

【问题讨论】:

  • 尝试为每个意图过滤器设置单独的接收器,有时清单合并会导致接收器无法工作的问题。我遇到了与您和我的类似的问题。

标签: android broadcast


【解决方案1】:

这通常是由于明显的合并问题而发生的。

将两个意图过滤器分别放在不同的接收者中,您的代码应该可以再次工作。如果它仍然不起作用,请告诉我们:)

【讨论】:

  • 我写了一条评论说它正在工作,但它可能被删除了。
  • 欢迎人 :) 接受答案,以免其他人继续检查此线程
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多