-2
即時通訊使用解析推送通知...即時通訊從解析,但由於消息沒有完全顯示在Android上,我決定按通知,並打開顯示完整通知的活動。我們必須從JSON中獲取「alert」和「title」,並將它們中的每一個放在TextView中,但我不知道如何從JSON中獲取文本。誰能幫忙?提前致謝。按通知,並打開一個活動,其中顯示全部通知
即時通訊使用解析推送通知...即時通訊從解析,但由於消息沒有完全顯示在Android上,我決定按通知,並打開顯示完整通知的活動。我們必須從JSON中獲取「alert」和「title」,並將它們中的每一個放在TextView中,但我不知道如何從JSON中獲取文本。誰能幫忙?提前致謝。按通知,並打開一個活動,其中顯示全部通知
公共類通知延伸活動{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notificationr);
TextView notification_title = (TextView) findViewById(R.id.notification_title);
Button main= (Button) findViewById(R.id.btn_bckMain);
main.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(Notification.this,Home.class);
startActivity(i);
}
});
Button home =(Button) findViewById(R.id.btn_bckHome);
home.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(Notification.this,Main.class);
startActivity(i);
}
});
ParseAnalytics.trackAppOpened(getIntent());
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String jsonData = extras.getString("com.parse.Data");
Log.v("Responce from JSON", jsonData);
try{
JSONObject notification = new JSONObject(jsonData);
String alert= notification.getString("alert");
Log.v("alert", alert);
Toast.makeText(getApplicationContext(), alert, Toast.LENGTH_LONG).show();
notification_title.setText(alert);
}
catch(JSONException e){
Toast.makeText(getApplicationContext(), "Something went wrong with the notification", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
其中JSON?你有一個網址來獲取數據? – 2014-09-20 10:12:38