按下通知并打开显示完整通知的活动

时间:2014-09-20 10:11:57

标签: android

我正在使用解析推送通知...我从解析收到通知但由于消息未在Android上完全显示,我决定按下通知并打开显示完整通知的活动。我们必须得到警告"和"标题"从JSON并将它们中的每一个放在TextView中,但我不知道如何从JSON获取文本。有人可以帮忙吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

公共类通知扩展了活动{

@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;
}

}