我想推送通知类似flipkart或myntra一样。 (推送通知将拿出一个大图像的细节有关的优惠,就点击其中将采取的优惠区)。 有谁知道如何把它做。 我的代码是这样的:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setDefaults(defaults)
.setStyle(new NotificationCompat.BigTextStyle().bigText("This is a test for push notification with big images."))
.setLargeIcon(icon)
.setSmallIcon(context.getApplicationInfo().icon)
.setWhen(System.currentTimeMillis())
.setContentTitle(extras.getString("title"))
.setTicker(extras.getString("title"))
.setContentIntent(contentIntent)
.setAutoCancel(true);
有时回来,我创建了一个拉要求这一点。
该显著代码:
public void createBigPicNotification(Context context, Bundle extras)
{
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String appName = getAppName(this);
.
.
.
String bigPictureUrl= null;
bigPictureUrl=extras.getString("bigPicture");
Bitmap bigPictureBMP = null;
if (bigPictureUrl != null) {
try {
URL url = new URL(bigPictureUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
bigPictureBMP = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
}
}
NotificationCompat.BigPictureStyle bigPicStyle = new
NotificationCompat.BigPictureStyle();
bigPicStyle.setBigContentTitle(extras.getString("title"));
bigPicStyle.setSummaryText(extras.getString("message"));
bigPicStyle.bigPicture(bigPictureBMP);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setDefaults(defaults)
.setSmallIcon(context.getApplicationInfo().icon)
.setWhen(System.currentTimeMillis())
.setTicker(extras.getString("title"))
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setStyle(bigPicStyle);
String message = extras.getString("message");
if (message != null) {
mBuilder.setContentText(message);
} else {
mBuilder.setContentText("<missing message content>");
}
String msgcnt = extras.getString("msgcnt");
if (msgcnt != null) {
mBuilder.setNumber(Integer.parseInt(msgcnt));
}
int notId = 0;
try {
notId = Integer.parseInt(extras.getString("notId"));
}
catch(NumberFormatException e) {
Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
}
catch(Exception e) {
Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
}
mNotificationManager.notify((String) appName, notId, mBuilder.build());
}