java - Android BOOT_COMPLETE not triggering (Shell does) -
i trying start service when phone boots up, , works shell command "adb shell broadcast -a android.intent.action.boot_completed -n com.example.adrian.wifi/.receiver" when restart phone nothing happens.
manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.adrian.wifi" > <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.change_wifi_state" /> <uses-permission android:name="android.permission.receive_boot_completed" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" > <service android:name=".wifi" android:enabled="true" android:exported="true" > </service> <receiver android:name=".receiver" android:enabled="true" android:exported="true" > <intent-filter> <action android:name="android.intent.action.boot_completed"/> </intent-filter> </receiver> </application>
receiver:
package com.example.adrian.wifi; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.util.log; public class receiver extends broadcastreceiver { private static final string tag = "com.example.adrian.wifi"; public receiver() { } @override public void onreceive(context context, intent intent) { log.i(tag, "starting"); intent myintent = new intent(context, wifi.class); myintent.addflags(intent.flag_activity_new_task); context.startservice(myintent); }
}
add below line intent-filter of reciever:
<category android:name="android.intent.category.default" />
Comments
Post a Comment