2011-12-11 5 views
10

알림 바를 누르면 내 앱이 실행될 알림 창이 나타납니다. 이 작업을 수행하는 데 문제가 없지만 사용자는 재부팅 후에도 알림이 나타나기를 원합니다. 그들에게는이 작업을 수행하는 다른 공급 업체의 응용 프로그램이 있습니다.재부팅 후 안드로이드 알림

알림을 표시하기 위해 앱이 실행 중이어야한다는 것을 모두 알 수 있습니다. 어떤 아이디어?

+0

나는 eSniff의 답변을 알고 있습니다. 하지만 내가 말하고있는 다른 앱은 실행중인 서비스가없고 앱 자체가 실행되고 있지 않지만 알림은 여전히 ​​존재하며 앱을 실행합니다. – miannelle2

+0

해결하셨습니까? 나는 똑같은 방법으로 궁금해하고있다. – bman

답변

10

재부팅 후 서비스를 시작하는 수신기를 추가해야합니다. 부팅 수신기에서

<service android:name="com.meCorp.service.MeCorpServiceClass"/> 
... 
<receiver android:name="com.meCorp.receiver.MyRebootReceiver"> 
<intent-filter> 
<action android:name="android.intent.action.BOOT_COMPLETED"/> 
</intent-filter> 
</receiver> 
... 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 

전체 부팅에 대한 매니페스트 레지스터에서

, 서비스를 시작합니다.

public class MyRebootReceiver extends BroadcastReceiver { 

     @Override 
     public void onReceive(Context context, Intent intent) { 
      Intent serviceIntent = new Intent(context, MeCorpServiceClass.class); 
      serviceIntent.putExtra("caller", "RebootReceiver"); 
      context.startService(serviceIntent); 
     } 
} 

다음은 서비스 클래스가 백그라운드에서 실행되는 예입니다.

public class MeCorpServiceClass extends IntentService{ 

     @Override 
     protected void onHandleIntent(Intent intent){ 
      String intentType = intent.getExtras().getString("caller"); 
      if(intentType == null) return; 
      if(intentType.Equals("RebootReceiver")) 
        //Do reboot stuff 
      //handle other types of callers, like a notification. 
     } 
    } 

또는 Urban AirShip과 같은 제 3자를 사용하면 모든 것을 처리 할 수 ​​있습니다.

+1

u는 boot_complete를 받기 위해서도 권한을 추가해야한다. –

+0

@android_hungry 고마워, 방금 했어. – eSniff

+0

welcome .. nice 2 c the acknowledgment –

관련 문제