获取解析推​​送通知的列表视图 [英] Getting Parse Push Notification in List view

查看:116
本文介绍了获取解析推​​送通知的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的解析推送通知我的应用程序,通知来不错,但在点击我需要向他们展示列表视图通知,我搜索的教程,但我找不到任何。请帮帮我 。请code解释,我是新来的Andr​​oid系统。提前致谢。
这里是我的自定义接收器。

 公共类CustomReciever扩展广播接收器{      NotificationCompat.Builder mBuilder;
      意图resultIntent;
  INT mNotificationId = 001;
   乌里notifySound;
   字符串警报;@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
    尝试{
        JSONObject的JSON =新的JSONObject(intent.getExtras()的getString(com.parse.Data)。);
        。警报= json.getString(警报)的toString();
    }赶上(JSONException E){    }
    mBuilder =新NotificationCompat.Builder(背景);
    mBuilder.setStyle(新NotificationCompat.BigTextStyle()bigText(警告)。);
    mBuilder.setPriority(Notification.PRIORITY_HIGH);
    mBuilder.setSmallIcon(R.drawable.syncytium);
    mBuilder.setContentText(警告);
    mBuilder.setContentTitle(合胞体);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    mBuilder.setAutoCancel(真);    resultIntent =新意图(背景下,com.omc.sunny.syncytium.syncytium.Notification.class);    的PendingIntent resultPendingIntent =
            PendingIntent.getActivity(上下文,0,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);    mBuilder.setContentIntent(resultPendingIntent);    NotificationManager notificationManager =
            (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);    notificationManager.notify(mNotificationId,mBuilder.build());
}
  }

这是我的Notification类

 公共类通知扩展AppCompatActivity {
    TextView的notifTv;   @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_notification);
    notifTv =(的TextView)findViewById(R.id.notif);}@覆盖
保护无效onNewIntent(意向意图){
    字符串消息= getIntent()getExtras()的getString(警告)。;
    notifTv.setText(消息);
} }


解决方案

不使用 getIntent(),使用意图在方式:

  @覆盖
    保护无效onNewIntent(意向意图){
        字符串消息= intent.getExtras()的getString(警告)。
        notifTv.setText(消息);
    }

I am using parse push notification for my app , the notification comes fine but on clicking the notification I need to show them in a list view , I searched for tutorials but I could not find any . Please help me . Please explain with code , I am new to android . Thanks in advance. here is my custom receiver.

      public class CustomReciever extends BroadcastReceiver {

      NotificationCompat.Builder mBuilder;
      Intent resultIntent;
  int mNotificationId = 001;
   Uri notifySound;
   String alert;

@Override
public void onReceive(Context context, Intent intent) {
    try{
        JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
        alert = json.getString("alert").toString();
    }catch (JSONException e){

    }
    mBuilder = new  NotificationCompat.Builder(context);
    mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(alert));
    mBuilder.setPriority(Notification.PRIORITY_HIGH);
    mBuilder.setSmallIcon(R.drawable.syncytium);
    mBuilder.setContentText(alert);
    mBuilder.setContentTitle("Syncytium");
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    mBuilder.setAutoCancel(true);

    resultIntent = new Intent(context, com.omc.sunny.syncytium.syncytium.Notification.class);

    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(context,0,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);

    NotificationManager notificationManager =
            (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);

    notificationManager.notify(mNotificationId,mBuilder.build());
}
  }

here is my Notification class

   public class Notification extends AppCompatActivity {
    TextView notifTv;

   @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notification);
    notifTv = (TextView)findViewById(R.id.notif);

}

@Override
protected void onNewIntent(Intent intent) {
    String message = getIntent().getExtras().getString("alert");
    notifTv.setText(message);
}

 }

解决方案

dont use getIntent() , use intent in method:

@Override
    protected void onNewIntent(Intent intent) {
        String message = intent.getExtras().getString("alert");
        notifTv.setText(message);
    }

这篇关于获取解析推​​送通知的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆