Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method setDefaultPushCallback from the type PushService is deprecated using android

I am newbie in android. I have been dealing with the problem of deprecated method at push service using parse services. I have followed similar question for the similar problem here but can't get the solution. In My main application class i am dealing with this problem, the code is given below for that one.

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 am using this one:

<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 have to use it like the following method, but i cant figure it out how to use this and resolve 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 for this problem. You help will be appreciated.

like image 776
using_coding Avatar asked Jun 25 '15 08:06

using_coding


1 Answers

Yes, PushService.setDefaultPushCallback() is deprecated now. All you have to do is to create your own subclass of ParsePushBroadcastReceiver. So in your Manifest file along with default Parse push receiver you should declare your Receiver subclass as following

 <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 receiver subclass your should override 'getActivity()` method

protected Class<? extends Activity> getActivity(Context context,
                                Intent intent) {
    return YourActivity.class;
}
like image 64
Oleg Osipenko Avatar answered Oct 12 '22 06:10

Oleg Osipenko