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에 의해 제공되기 때문이다.
도움을 주시면 대단히 감사하겠습니다.
'de.myapp.android.MESSAGE'란 무엇입니까? – StarPinkER