简体   繁体   English

如果安装了另一个应用程序,则BOOT_COMPLETED接收器不起作用

[英]BOOT_COMPLETED receiver not working if another application is installed

Basically I've got a boot receiver set up like so: 基本上我已经建立了一个启动接收器,如下所示:

<receiver
        android:name="com.xxx.xxx.XXX.BootUpReciever"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter android:priority="999" >
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver> code here

Now this seems to work fine most of the time. 现在,这似乎在大多数时间都可以正常工作。 It will boot fire on boot fine and continue doing what it needs to do. 它将在启动正常时启动,并继续执行所需的操作。 However, if I combine this with another application I develop, the receiver never gets called despite still being registered. 但是,如果将其与我开发的另一个应用程序结合使用,即使仍在注册中,也永远不会调用接收方。

I always make sure to run the application first so it is registered, so it's not that. 我总是确保先运行该应用程序,以便它被注册,所以不是那样。 If I uninstall the other application, it works. 如果我卸载其他应用程序,则可以使用。 They do have a shared user, but I don't think that has much to do with it as I use that across a number of applications which work fine in combination. 他们确实有一个共享用户,但是我认为这与它没有多大关系,因为我将其用于许多可以很好地组合使用的应用程序中。 It's just this one particular application it does not get along with. 只是这一个特定的应用程序而已。

EDIT: 编辑:

I do have <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> , otherwise it would not work at all. 我确实有<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> ,否则根本无法使用。

And the boot receiver itself: 以及引导接收器本身:

public class BootUpReciever extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent args) {
    incBootCounter(context);
    Intent i = new Intent(context, HomeScreenActivity.class);  
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
}

private void incBootCounter(Context ctx) {
    SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(ctx);
    if (s != null) {
        Editor edit = s.edit();
        if (edit != null) {
            edit.putInt("how_many_times_have_we_booted", s.getInt("how_many_times_have_we_booted", 0) + 1);
            edit.commit();
        }
    }
}

} }

Just to point out, this isn't an application that goes on the Google Play store or anything. 只是要指出,这不是Google Play商店中的任何应用程序。 It's a very specific application that is only deployed to devices we own as a company. 这是一个非常特定的应用程序,仅部署到我们作为公司拥有的设备上。

EDIT 2: 编辑2:

I've found some help in the logs. 我在日志中找到了一些帮助。 With the other application installed I get this message: 安装了其他应用程序后,我收到以下消息:

W/BroadcastQueue(  986): Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x8000010 (has extras) } to com.xxx.xxx.xxxxxxxxx/.BootUpReciever requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)

Without the other application I get this message: 没有其他应用程序,我会收到以下消息:

I/ActivityManager(  980): Start proc com.xxx.xxx.xxxxxx for broadcast com.sps.smc.SMCKiosk/.BootUpReciever: pid=1656 uid=10109 gids={50109, 3003, 3002, 3001, 1028, 1015}

Try something like: 尝试类似:

public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
      if (context != null) {
        // your codes here
      }
   }
}

The first check ensures that only action equals Intent.ACTION_BOOT_COMPLETED will be processed. 第一个检查确保仅处理等于Intent.ACTION_BOOT_COMPLETED操作。 The second check ensures that only a valid context is used to execute the codes. 第二次检查确保仅使用有效上下文执行代码。

Also, the AndroidManifest.xml should have the following declarations: 另外,AndroidManifest.xml应具有以下声明:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver
   android:name="com.xxx.xxx.XXX.BootUpReciever">
   <intent-filter android:priority="999" >
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      <action android:name="android.intent.action.QUICKBOOT_POWERON" />    
      <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
</receiver>

Managed to solve it. 设法解决它。

My problem was that because it was a shared user, I had to put the permission in the other manifest (or at least I think that's what the issue was). 我的问题是,因为它是一个共享用户,所以我不得不将许可放到另一个清单中(或者至少我认为这就是问题所在)。

For some reason it was revoking it because it was not in both manifests. 由于某种原因,它被撤销,因为它不在两个清单中。 Why it worked with the same shared user in other applications without the same permissions mirroring across is unknown to me at this point. 目前,我不知道为什么它可以与其他应用程序中的同一共享用户一起使用,而没有跨相同的权限进行镜像。 Might be the order in which it loads the packages at a guess. 可能是猜测时加载程序包的顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM