我是android的新手。我一直在使用deprecated method
服务处理push service
parse
的问题。我在这里遇到类似问题的类似问题,但无法得到解决方案。在我的主要application class
我正在处理这个问题,下面给出了代码。
public class MApplication extends Application {
private static MApplication mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
Parse.initialize(this, JNI.stringFromJNI001(), JNI.stringFromJNI010());
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, MainLandingActivity.class);
// setDefaultPushCallback shows deprecated method here..
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
public static MApplication getInstance() {
return mInstance;
}
}
在我的manifest
我使用的是这个:
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
从这个链接 https://teamtreehouse.com/forum/app-crash-on-push-test我看到我必须像下面的方法一样使用它,但我无法弄清楚如何使用它并解决我的问题。
public class Receiver extends ParsePushBroadcastReceiver {
@Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
请帮我解决这个问题。您将获得帮助。
答案 0 :(得分:4)
是的,PushService.setDefaultPushCallback()
现已弃用。您所要做的就是创建自己的 ParsePushBroadcastReceiver 子类。因此,在您的Manifest文件中以及默认的Parse推送接收器中,您应该将Receiver子类声明为以下
<receiver android:name="com.yourProject.YourReceiver" android:exported=false>
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.OPEN" />
<action android:name="com.parse.push.intent.DELETE" />
</intent-filter>
</receiver>
然后你的接收器子类你应该覆盖'getActivity()`方法
protected Class<? extends Activity> getActivity(Context context,
Intent intent) {
return YourActivity.class;
}