1

是否可以在通知中从 URI 添加自定义图像?例如:

Notification notification = new Notification(R.drawable.ic_launcher, "something", System.currentTimeMillis());

我会从 URI 中插入图像,而不是从可绘制资源中插入图像。提前致谢

4

1 回答 1

0

试试这个代码

// Large icon for notification with add a custom image from URI 
Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
builder.setLargeIcon(bmp);

Notiifcation Builder 中的上述代码。

public void DisplayNotification() {

// Use NotificationCompat.Builder to set up our notification.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

//icon appears in device notification bar and right hand corner of notification
builder.setSmallIcon(R.drawable.ic_stat_notification);

// This intent is fired when notification is clicked
Intent tapIntent = new Intent(CurrentActivity.this, SecondActivity.class);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, tapIntent, 0);

// Set the intent that will fire when the user taps the notification.
builder.setContentIntent(pendingIntent);

// Large icon appears on the left of the notification
 Bitmap bmp=BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
builder.setLargeIcon(bmp);

// Content title, which appears in large type at the top of the notification
builder.setContentTitle("Notifications Title");

// Content text, which appears in smaller text below the title
builder.setContentText("Your notification content here.");

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

// Will display the notification in the notification bar
notificationManager.notify(NOTIFICATION_ID, builder.build());
}

快乐编码:)

于 2015-12-09T07:55:17.797 回答