service not getting started at boot

2019-09-08 04:13发布

i have a receiver that starts a service at boot but the receiver never gets fired when at boot

manifest

        <service android:enabled="true" android:name=".BatteryService"></service>

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

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

why does it not work, everything looks correct

if i open my app the service starts fine

Receiver class

    public class BatteryReciever extends BroadcastReceiver {

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        arg0.startService(new Intent(arg0, BatteryService.class));
    }//end onRecieve
}

1条回答
不美不萌又怎样
2楼-- · 2019-09-08 04:32

tyzyj,

It looks like you may have misspelled the word receive in multiple places as recieve.

Try...

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

</receiver>

unless the class name is misspelled as well? You may want to post the code for that Receiver class.

查看更多
登录 后发表回答