sti*_*boe 11 notifications android broadcastreceiver push-notification parse-platform
我想从Parse接收推送通知并打开List活动并在开始活动之前使用intent.putextra("dataFromParse").我能够接收推送,但只使用以下命令打开MainActivity:
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
Run Code Online (Sandbox Code Playgroud)
我希望将此作为默认值,但也应该能够启动List活动.我也试过使用客户接收器,但是我只能在接收推送时直接打开活动,而不是点击它.
manifest.xml文件:
<receiver android:name="com.example.Push android:exported="false">
<intent-filter>
<action android:name="com.example.UPDATE_STATUS" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
Push.java:
public class Push extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//Start activity
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定的是我应该如何在后台捕获推送,并说当用户单击通知时它应该使用特定的intent.putExtra("dataFromParse")打开List活动.我应该在哪里编码以及如何编码?在MainActivity中,在List活动中,还是在客户接收器上执行其他操作?
sti*_*boe 13
解决了它,将默认活动作为MainActivity,但检查意图,如果"com.parse.Data"中有什么内容,我将启动一个新意图.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String jsonData = extras.getString("com.parse.Data");
JSONObject json = new JSONObject(jsonData);
String pushStore = json.getString("data");
if(pushStore!=null) {
Intent pushIntent = new Intent();
pushIntent.setClassName(MainActivity.this, "package.name.List");
pushIntent.putExtra("store", pushStore);
startActivity(pushIntent);
}
Run Code Online (Sandbox Code Playgroud)
然后用json发送推送:{"alert":"Test","data":"store1"}
@arvindwill希望这会有所帮助.
| 归档时间: |
|
| 查看次数: |
13029 次 |
| 最近记录: |