大家都有这个针对Android的Push Notification的激烈问题。我设置了一个Custom接收器。我能够发送并查看推送通知。但是,当我点击通知时,我会收到以下错误。
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)
但是你可以看到我有启动活动的意图键。它开始让我恼火,所以希望有人可以分享一些经验:)
这是我的自定义接收器: 包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