2013-03-05 3 views
0

Phone의 부팅이 완료되면 새로운 서비스를 시작하고 싶습니다.브로드 캐스트에서 서비스가 null입니다. Receiver

@Override 
    public void onReceive(final Context context, final Intent intent) { 

    if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) { 
     Intent mServiceIntent = new Intent("com.android.reminder.BootService"); 

     //mServiceIntent.setAction("com.android.reminder.BootService"); 
     ComponentName service = context.startService(mServiceIntent); 

     if (service==null) { 
      // something really wrong here 
      Toast.makeText(context, "Sorry, Service is found null", 
        Toast.LENGTH_LONG).show(); 

     }else{ 
      Toast.makeText(context, "Service is not null", 
        Toast.LENGTH_LONG).show(); 
     } 
    } 
} 

을 다음과 매니페스트 파일에 선언이다 그래서 나는 그것을위한 방송 수신기를 생성 -

 ..... 
    <service 
     android:enabled="true" 
     android:name="com.android.reminder.BootService"> 
    </service> 

    <receiver 
     android:name="AlarmReceiver" 
     android:process=":remote" > 
    </receiver> 
    <receiver 
     android:enabled="true" 
     android:name=".BootReceiver" > 
     <intent-filter > 
      <action android:name="android.intent.action.BOOT_COMPLETED" > 
      </action> 
     </intent-filter> 
    </receiver> 
</application> 

가 나는 토스트가 "죄송합니다, 서비스가 null의 발견"되고 서비스가 시작되지 않은 발견 .. ...

제발 도와주세요 나를 .... 사전에 들으 ..

답변

2

을 필요로 할 수 있음
Intent mServiceIntent = new Intent(context, BootService.class); 
+0

정말 고마워요 .... –

+0

다행입니다. 이 대답을 수락하십시오. – Sunny

관련 문제