2013-03-14 2 views
3

Here's 내 문제를 시작 안드로이드 BootReceiver을 방지 :주요 활동을

내 안드로이드 응용 프로그램은 PushNotification - 관리자 (PushWoosh)를 초기화 부팅 수신기를 등록합니다. 기기를 재부팅 한 후에도 사용자가 앱을 수동으로 시작하지 않아도 푸시 알림을 수신 할 수 있어야합니다.

이 방법은 작동하지만 기기가 재부팅되면 앱 기본 활동 (MainMenuActivity)이 시작되어 포 그라운드로 이동합니다.

Here's 침범 코드 :

의 AndroidManifest.xml :

<!-- Re-register PushManagers after reboot --> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 

<application 
android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@android:style/Theme.Black.NoTitleBar"> 

<!-- PushWoosh --> 
<activity android:name="com.arellomobile.android.push.PushWebview"/> 
<activity android:name="com.arellomobile.android.push.MessageActivity"/> 
<activity android:name="com.arellomobile.android.push.PushHandlerActivity"/> 

<!-- PushWoosh --> 
<receiver 
    android:name="com.google.android.gcm.GCMBroadcastReceiver" 
    android:permission="com.google.android.c2dm.permission.SEND"> 

    <intent-filter> 
     <action android:name="com.google.android.c2dm.intent.RECEIVE"/> 
     <action android:name="com.google.android.c2dm.intent.REGISTRATION"/> 
     <category android:name="de.myapp.android"/> 
    </intent-filter> 
</receiver> 

<!-- PushWoosh --> 
<service android:name="com.arellomobile.android.push.PushGCMIntentService"/> 

<!-- Boot-Receiever --> 
<receiver android:name="de.myapp.android.startup.BootCompleteReceiver"> 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED"/> 
    </intent-filter> 
</receiver> 

<activity 
    android:name="de.myapp.android.activity.MainMenuActivity" 
    android:configChanges="orientation|keyboardHidden|screenSize" 
    android:label="@string/app_name" 
    android:launchMode="singleTop" 
    android:screenOrientation="portrait" 
    android:windowSoftInputMode="adjustPan"> 

    <intent-filter> 
     <!-- Starten bei Klick auf Launcher Icon --> 
     <action android:name="android.intent.action.MAIN"/> 
     <category android:name="android.intent.category.LAUNCHER"/> 
    </intent-filter> 

    <intent-filter> 
     <!-- Starten bei Erhalt einer Push Notification --> 
     <action android:name="de.myapp.android.MESSAGE"/> 
     <category android:name="android.intent.category.DEFAULT"/> 
    </intent-filter> 

</activity> 

BootCompleteReceiver.java :

public class BootCompleteReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent i) { 
     PushWooshHelper.setupPushNotifications(context.getApplicationContext()); 
    } 

} 

PushWooshHelper.java :

public class PushWooshHelper { 

    public static void setupPushNotifications(Context context) { 
     PushManager pushManager = new PushManager(context, AppIDs.PUSHWOOSH_APP_ID, AppIDs.GCM_PROJECT_ID); 
     pushManager.onStartup(context); 
     pushManager.startTrackingGeoPushes(); 
    } 

} 

MainMenuActivity. 자바 :

public class MainMenuActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     ... 
    } 


    private void checkMessage(Intent intent) { 

     if (intent != null) { 

      String log = "PUSH NOTIFICATION RECEIVED."; 

      if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT)) { 
       log += "message: " + intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT); 
      } 
      else if (intent.hasExtra(PushManager.REGISTER_EVENT)) { 
       log += "<register>"; 
      } 
      else if (intent.hasExtra(PushManager.UNREGISTER_EVENT)) { 
       log += "<unregister>"; 
      } 
      else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT)) { 
       log += "<register error>"; 
      } 
      else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT)) { 
       log += "<unregister error>"; 
      } 
     } 
    } 

    @Override 
    protected void onNewIntent(Intent intent) { 

     super.onNewIntent(intent); 

     setIntent(intent); 
     checkMessage(intent); 

     setIntent(new Intent()); 
    } 
} 

주의 사항 : 나는 PushManager.onStartup (에 액세스 할 수없는), 그것은 PushWoosh에 의해 제공되기 때문이다.

도움을 주시면 대단히 감사하겠습니다.

+0

'de.myapp.android.MESSAGE'란 무엇입니까? – StarPinkER

답변

0

그건 이상합니다. Pushwoosh는 장치를 다시 시작한 후에 작동하는 GCM을 사용합니다. 푸시 알림을 한 번 등록한 다음 재시작 한 후 GCM이 푸시 알림을 처리해야합니다.

+0

당신 말이 맞아요. 재부팅 후 푸시 알림이 작동하지 않기 때문에 부트 수신기를 구현했습니다. 하지만 이것은 또 다른 오류로 인한 것이므로 올바르게 설정하면 각 부팅시 PushManager를 수동으로 인스턴스화 할 필요가 없습니다. –

관련 문제