问题描述
我一直面临的整个问题就是这行代码
The whole problem i have been facing is with this line of code
PushService.setDefaultPushCallback(this,MainActivity.class);
PushService.setDefaultPushCallback(this, MainActivity.class);
在导入PushService时,不建议使用setDefaultPushCallback |().为什么会这样呢?我收到通知,但是在点击应用程序时崩溃了.当应用未运行时也无法接收.
on importing PushService the setDefaultPushCallback|() got deprecated. Why is this happening. I receiving the notifications but on tap app is being crashed. Also not receiving when the app isn't running.
推荐答案
我找到了解决方案,它很简单.
我发现了同样的问题 https://stackoverflow.com/a/26180181/3904085
I have found the solution and it is quite simple.
I found the same question https://stackoverflow.com/a/26180181/3904085
"花了几个小时后.找到了一个解决方案:实现您的接收器并扩展ParsePushBroadcastReceiver类.
"After spending few hours. Found a solution: Implement your receiver and extends ParsePushBroadcastReceiver class.
Receiver.java
Receiver.java
public class Receiver extends ParsePushBroadcastReceiver {
@Override
public void onPushOpen(Context context, Intent intent) {
Log.e("Push", "Clicked");
Intent i = new Intent(context, HomeActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
在清单中使用它(而不是使用ParsePushBroadcastReceiver)
Use it in manifest, (Instead of using ParsePushBroadcastReceiver)
项目清单的代码:
<receiver
android:name="your.package.name.Receiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
"归功于@Ahmad Raza
"Credits to @Ahmad Raza
这篇关于不推荐使用PushService类型的方法setDefaultPushCallback(Context,Class<?extended Activity>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!