本文介绍了推送通知不正确的 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想加入一个推送通知的形象和动作按钮。但是,不能正常工作。
I am trying to add image and action buttons in a push notification. But that is not working properly.
通知看起来像这样当我第一次点击按钮,并移动到其他活动(图像丢失):
Notification looks like this when I first click on the button and move to other activity (The image is missing) :
但是,如果我回去,然后再次单击该按钮,图像看起来有多个按钮:
另外,未示出的通知的情况下的文本。这里是code:
Also, the context text of the notification is not shown. Here is the code :
notification.setContentTitle("Successfully Signed Up"); notification.setContentText("Hi, you just Signed Up as a Vendor"); notification.setWhen(System.currentTimeMillis()); notification.setSmallIcon(R.mipmap.ic_launcher); Intent i=new Intent(this,OrderTypes.class); PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0); notification.addAction(R.mipmap.ic_launcher,"Accept",pi); notification.addAction(R.mipmap.ic_launcher, "Decline", pi); /*NotificationCompat.MediaStyle mediaStyle=new NotificationCompat.MediaStyle(); MediaSessionCompat mediaSession=new MediaSessionCompat(this,TAG); mediaStyle.setShowActionsInCompactView(1); mediaStyle.setMediaSession(mediaSession.getSessionToken()); notification.setStyle(mediaStyle);*/ NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle(); //notiStyle.setBigContentTitle("Big Picture Expanded"); //notiStyle.setSummaryText("Nice big picture."); new Thread(new Runnable() { @Override public void run() { try { remote_picture = BitmapFactory.decodeStream((InputStream) new URL(getIntent().getExtras().getString("imageurl")).getContent()); } catch (IOException e) { e.printStackTrace(); } } }).start(); notiStyle.bigPicture(remote_picture); notification.setStyle(notiStyle); Intent intent = new Intent(this, VendorDetails.class); intent.putExtra("Phone", num); PendingIntent pendingIntent = PendingIntent.getActivity(Verify.this, 0, intent, 0); notification.setContentIntent(pendingIntent); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(uniqueID, notification.build());新的完整更新功能:的
The new Complete Updated Function :
public void defineNotification(String num) { new Thread(new Runnable() { public void run() { try { notification.setContentTitle("New Order Received") notification.setContentText("Train No.12724 \n Amount 500"); notification.setWhen(System.currentTimeMillis()); notification.setSmallIcon(R.drawable.omitra_notification_icon); Intent i = new Intent(this, OrderTypes.class); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); notification.addAction(R.drawable.pink_accept, "Accept", pi); notification.addAction(R.drawable.pink_decline, "Decline", pi); notification.setPriority(Notification.PRIORITY_MAX); NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle(); //String url=getIntent().getExtras().getString("imageurl"); //ImageLoader imageLoader=new ImageLoader(); try { remote_picture = BitmapFactory.decodeStream((InputStream) new URL(getIntent().getExtras().getString("imageurl")).getContent()); } catch (IOException e) { e.printStackTrace(); } notiStyle.setSummaryText("Amount : 500"); notiStyle.bigPicture(remote_picture); notification.setStyle(notiStyle); Intent intent = new Intent(this, VendorDetails.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("Phone", num); PendingIntent pendingIntent = PendingIntent.getActivity(Verify.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(pendingIntent); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //nm.cancel(uniqueID); nm.notify(uniqueID, notification.build()); } catch (IOException e) { e.printStackTrace(); } } }).start(); }有谁知道,如果我错过了这里的东西吗?
Does anybody know if I missed something here ?
推荐答案试试这个 -
public void defineNotification(String num) { new Thread(new Runnable() { public void run() { try { Intent i = new Intent(Verify.this, OrderTypes.class); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); notification.setContentTitle("New Order Received") notification.setContentText("Train No.12724 \n Amount 500"); notification.setWhen(System.currentTimeMillis()); notification.setSmallIcon(R.drawable.omitra_notification_icon); notification.addAction(R.drawable.pink_accept, "Accept", pi); notification.addAction(R.drawable.pink_decline, "Decline", pi); notification.setPriority(Notification.PRIORITY_MAX); remote_picture = BitmapFactory.decodeStream((InputStream) new URL(getIntent().getExtras().getString("imageurl")).getContent()); NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle(); notiStyle.setSummaryText("Amount : 500"); notiStyle.bigPicture(remote_picture); notification.setStyle(notiStyle); Intent intent = new Intent(Verify.this, VendorDetails.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("Phone", num); PendingIntent pendingIntent = PendingIntent.getActivity(Verify.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); notification.setContentIntent(pendingIntent); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(uniqueID, notification.build()); } catch (IOException e) { e.printStackTrace(); } } }).start(); }更多推荐
推送通知不正确的
发布评论