일단 퍼미션을 지정합니다.
<!-- Boot Config -->
<receiver android:name=".BootBroadcast" android:enabled="true"
android:exported="false"
android:label="androesServiceManager"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
<receiver android:name=".BootBroadcast" android:enabled="true"
android:exported="false"
android:label="androesServiceManager"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
BooBroadcast.java
public class BootBroadcast extends BroadcastReceiver {
static final String TAG = "ANDROES";
private final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
//리시버가 발동시 나의 서비스 실행
Logger.d(TAG, "BOOT_ACTION : onReceive");
if (intent.getAction().equals(BOOT_ACTION)) {
// boot 시 shared값을 못불러오네~음
final SharedPreferences prefs = context.getSharedPreferences("androesPrefName", 0);
String status = prefs.getString("status", "");
Logger.d(TAG, "BOOT_ACTION : " + status);
if (status.equals("start")) {
// Logger.d(TAG, "BOOT_ACTION : cylost service ON");
context.startService(new Intent(context, androesService.class));
} else {
// Logger.d(TAG, "BOOT_ACTION : cylost service OFF");
}
}
}
}
static final String TAG = "ANDROES";
private final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
//리시버가 발동시 나의 서비스 실행
Logger.d(TAG, "BOOT_ACTION : onReceive");
if (intent.getAction().equals(BOOT_ACTION)) {
// boot 시 shared값을 못불러오네~음
final SharedPreferences prefs = context.getSharedPreferences("androesPrefName", 0);
String status = prefs.getString("status", "");
Logger.d(TAG, "BOOT_ACTION : " + status);
if (status.equals("start")) {
// Logger.d(TAG, "BOOT_ACTION : cylost service ON");
context.startService(new Intent(context, androesService.class));
} else {
// Logger.d(TAG, "BOOT_ACTION : cylost service OFF");
}
}
}
}