0
大家好,這個推送通知的android有一個激烈的問題。我設置了一個自定義接收器。我可以發送並查看推送通知。但是當我點擊通知時,我收到下面的錯誤。嘗試點擊推送通知時出現錯誤Android
FATAL EXCEPTION: main
Process: com.rocketapptechnologies.listout, PID: 29566
java.lang.RuntimeException: Unable to start receiver com.rocketapptechnologies.receiver.ParseReceiver: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586)
at android.app.ActivityThread.access$1700(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5310)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:1130)
at android.app.ContextImpl.startActivity(ContextImpl.java:1117)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:311)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:311)
at com.rocketapptechnologies.receiver.ParseReceiver.onPushOpen(ParseReceiver.java:24)
at com.parse.ParsePushBroadcastReceiver.onReceive(ParsePushBroadcastReceiver.java:123)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2579)
at android.app.ActivityThread.access$1700(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1403)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5310)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
但是正如你所看到的,我有意圖鍵來啓動活動。它開始惹惱我,所以希望有人會有一些經驗分享:)
這是我的自定義接收器: package com.rocketapptechnologies.receiver;
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import com.parse.ParsePushBroadcastReceiver;
import com.rocketapptechnologies.listout.LoginActivity;
/**
* Created by KieranMcc on 20/01/2016.
*/
public class ParseReceiver extends ParsePushBroadcastReceiver {
public ParseReceiver(){
}
@Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
Intent i = new Intent(context, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
這是ManifestFiles接收機和服務標籤
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
<receiver android:name="com.rocketapptechnologies.receiver.ParseReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.rocketapptechnologies.listout" />
</intent-filter>
</receiver>
找不到任何事情來幫助我只需點擊通知並打開簡單的活動我想用它來測試。
感謝您閱讀我的問題,真的希望你們能幫助,所以我其實可以繼續我的應用程序的xD
這是關於推送通知的部分知識!這是完美的!要穿過這個地段並研究它。如果它有效,我會設置這個答案爲正確的:)。感謝真正快速反應的人! – SmiffyKmc
沒問題。我不知道該視頻是否比爲你的博客更有意義,但兩者都處於相同的鏈接。 – TooManyEduardos
感謝您的鏈接和視頻。它清除了一些東西,但仍然得到錯誤說,從Activity上下文外調用startActivity()需要FLAG_ACTIVITY_NEW_TASK標誌。這真的是你想要的嗎?每當我點擊通知:/ – SmiffyKmc