브로드캐스트
public class RestartService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// 폰 재부팅시 서비스 등록
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, ServiceClass.class);
context.startService(i);
}
// 서비스 죽일때 알람으로 다시 서비스 등록
if (intent.getAction().equals("ACTION.RESTART.ServiceClass")) {
Intent i = new Intent(context, ServiceClass.class);
context.startService(i);
}
}
}
매니페스트
<!-- 부팅 앱 자동 실행 매니퍼스트 파일 권한 등록-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"
<receiver android:name="health.all.water_bottle.RestartService"
android:enabled="true"
android:exported="false"
android:label="RestartService"
android:process=":remote" >
<intent-filter>
<action android:name="ACTION.RESTART.ServiceClass" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
서비스
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, " +++ onStartCommand Service +++");
if(intent.getStringExtra("finish") != null){
stopForeground(true);
stopSelf();
mBluetoothAdapter.disable();
System.exit(0);
}else if(intent.getStringExtra("phone") != null){
inputnumber = intent.getStringExtra("phone");
Log.i(TAG, "인텐드로 넘어 온 전화번호 : " + inputnumber);
showNotification();
}
return Service.START_REDELIVER_INTENT; //전화 번호 값 유지하기 위해서
}
재부팅시 오류가 떠요.. 로그캣으로 원인을 찾고 싶은데 부팅시에는 로그캣이 안되서 원인을 찾을 수가 없네요
어떻게 처리해야하나요?? 알려주시면 감사하겠습니다.
부탁드립니다.