سؤال

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.

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. It's a very specific application that is only deployed to devices we own as a company.

EDIT 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}
هل كانت مفيدة؟

المحلول 2

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.

نصائح أخرى

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. The second check ensures that only a valid context is used to execute the codes.

Also, the AndroidManifest.xml should have the following declarations:

<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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top