The setDefaultPushCallback method of type PushService deprecated using android

I am new to android. I ran into the deprecated method problem in push service using parse services. I came across a similar question for a similar problem, but cannot solve the problem. In My main application class I am dealing with this problem, the code is below for this.

 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; } } 

In my manifest I use this:

 <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> 

From this link https://teamtreehouse.com/forum/app-crash-on-push-test I saw that I should use it as the next method, but I cannot figure out how to use this and solve my problem.

 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); } } 

Please help me with this problem. You will be very grateful.

+6
source share
1 answer

Yes, PushService.setDefaultPushCallback() deprecated. All you have to do is create your own subclass of ParsePushBroadcastReceiver . Thus, in your manifest file, along with the default Parse push receiver, you must declare your Receiver subclass as follows

  <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> 

And then your subclass of your receiver should override the getActivity () method

 protected Class<? extends Activity> getActivity(Context context, Intent intent) { return YourActivity.class; } 
+4
source

Source: https://habr.com/ru/post/989725/


All Articles