我使用Parse 1.7.1 sdk版本为我的Android应用设置了解析通知。
但是在新的android中,这个带解析的方法说调用是折旧的。
PushService.setDefaultPushCallback(this, MainActivity.class);
但是当它被删除时,我会在网站上看到通知从parse.com发送,但它没有到达手机?
如何更改以便推动到达?不使用折旧方法?
感谢您的帮助。
答案 0 :(得分:1)
尝试扩展ParsePushBroadcastReceiver类并使用其
<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;
用这个:
<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;
如果你想打开一个活动 onPushOpen ,这里有一个样本:
@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;
这是一个扩展ParsePushBroadcastReciever类
的示例类
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;