android-parse-titanium-module icon indicating copy to clipboard operation
android-parse-titanium-module copied to clipboard

Push notification receiver not working

Open yagitoshiro opened this issue 9 years ago • 0 comments

Looks like Parse SDK broke backward compatibility. Formerly all you need to do is just call PushService.setDefaultPushCallback and add intent-filter to AndroidManifest.xml. But now you have to implement your own receiver which extends ParsePushBroadcastReceiver, or you'll suffer from ActivityNotFoundException over and over again.

My solution is simply add Receiver class that extends ParsePushBroadcastReceiver. You have to override onPushOpen method to respond and boot your app on user clicking push notification. It goes like this:

package your.cool.package.name;

import org.appcelerator.titanium.TiApplication;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.parse.ParsePushBroadcastReceiver;

public class Receiver extends ParsePushBroadcastReceiver {
    @Override
    public void onPushOpen(Context context, Intent intent) {
        Log.e("Push", "Clicked");
        Bundle bundle = intent.getExtras();
        Activity activity = TiApplication.getAppRootOrCurrentActivity();
        Context appContext = activity.getApplicationContext();
        Intent i = new Intent(appContext, activity.getClass());
        i.putExtras(bundle);
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

yagitoshiro avatar Jun 18 '15 18:06 yagitoshiro