简体   繁体   中英

Android BroadcastReceiver not working when app is installed from play store

I have a service that is getting battery updates via Intent.ACTION_BATTERY_CHANGED:

batteryFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
batteryReceiver = new BatteryReceiver();

and the receiver:

public void onReceive(Context context, Intent intent) {

    String action = intent.getAction();
    if(action.equals(Intent.ACTION_POWER_CONNECTED)) {
        onBattery = false;
        Log.w("battery","on power");
    }
    else if(action.equals(Intent.ACTION_POWER_DISCONNECTED)) {
        Log.w("battery","on battery");
        onBattery = true;
    }
}

This works exactly as expected when the app is installed via USB debugging. After I published this to the play store and did a fresh install from there, it doesn't work. Other receivers aren't working in the app either. The rest of the app appears to be working properly, just no broadcast receivers are working. What could cause this to happen?

This is android 2.2 and it is an update to an app that was already in the store, the receiver was working properly before the update also.

如果您在Android 3.1+上运行,并且您没有手动运行其中一个组件(例如,从启动器启动活动),则您的所有清单注册的BroadcastReceiver都不会起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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