Android - 无法从Parse.com接收推送

时间:2014-12-03 04:22:27

标签: java android parse-platform push-notification

我使用Parse 1.7.1 sdk版本为我的Android应用设置了解析通知。

但是在新的android中,这个带解析的方法说调用是折旧的。

PushService.setDefaultPushCallback(this, MainActivity.class);

但是当它被删除时,我会在网站上看到通知从parse.com发送,但它没有到达手机?

如何更改以便推动到达?不使用折旧方法?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

尝试扩展ParsePushBroadcastReceiver类并使用其

  • OnPushRecieve(在状态栏中显示通知之前做某事)
  • OnPushOpen(用户打开时执行某些操作,例如打开活动)
  • getNotification和
  • onPushDismiss方法
    并在清单文件中替换



<receiver android:name="com.parse.ParsePushBroadcastReceiver" 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>
&#13;
&#13;
&#13;

用这个:

&#13;
&#13;
 <receiver
            android:name="com.example.parse.Notifications.NotificationsReciever"
            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>
&#13;
&#13;
&#13;

如果你想打开一个活动 onPushOpen ,这里有一个样本:

&#13;
&#13;
@Override
	protected void onPushOpen(Context context, Intent intent) {
		// TODO Auto-generated method stub
		Intent i = new Intent(context, PushNotificationHandler.class);
		i.putExtras(intent.getExtras());
		i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(i);
	}
&#13;
&#13;
&#13;

这是一个扩展ParsePushBroadcastReciever类

的示例类

&#13;
&#13;
public class NotificationsReciever extends ParsePushBroadcastReceiver {

	@Override
	protected Class<? extends Activity> getActivity(Context arg0, Intent arg1) {
		// TODO Auto-generated method stub

		return ParseStarterProjectActivity.class;
	}

	@Override
	protected Notification getNotification(Context context, Intent intent) {
		// TODO Auto-generated method stub
		return super.getNotification(context, intent);
	}

	@Override
	protected void onPushDismiss(Context context, Intent intent) {
		// TODO Auto-generated method stub
		super.onPushDismiss(context, intent);
	}

	@Override
	protected void onPushOpen(Context context, Intent intent) {
		// TODO Auto-generated method stub
		Intent i = new Intent(context, PushNotificationHandler.class);
		i.putExtras(intent.getExtras());
		i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(i);
	}

	@Override
	protected void onPushReceive(Context context, Intent intent) {
	//here You can handle push before appearing into status e.g if you want to stop it.
		super.onPushReceive(context, intent);
	 
	}

}
&#13;
&#13;
&#13;