Android RemoteViews setImageViewBitmap()不工作
我正在开发一个简单的android应用程序,带有自定义通知的布局。为此,我使用远程视图。我的布局中有一个ImageView,但无法将位图设置为它Android RemoteViews setImageViewBitmap()不工作,android,android-notifications,remoteview,Android,Android Notifications,Remoteview,我正在开发一个简单的android应用程序,带有自定义通知的布局。为此,我使用远程视图。我的布局中有一个ImageView,但无法将位图设置为它 layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap) 我使用以下代码设置位图: layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap) 我还尝试使用canvas,但这对我没有帮助: layout.setImage
layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap)
我使用以下代码设置位图:
layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap)
我还尝试使用canvas,但这对我没有帮助:
layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap)
val proxy = Bitmap.createBitmap(bitmap.width, bitmap.height, Bitmap.Config.ARGB_8888)
val c = Canvas(proxy)
c.drawBitmap(bitmap, Matrix(), null)
layout.setImageViewBitmap(R.id.noteNotificationImage, proxy)
位图不是空的,当我在简单布局中使用它时,一切都很好,而不是在RemoteView中
layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap)
有人能帮我吗?我不知道问题出在哪里,但这段代码对我来说运行良好
layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap)
@SuppressLint("NewApi")
public void customNotification(String title, String description, String image, Bitmap bitmap) {
Intent intent = new Intent(mContext,Activity.class);
long when = System.currentTimeMillis();
int icon = getNotificationIcon();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.small_notification);
RemoteViews expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.big_notification);
Notification notification = new Notification(icon, getResources().getString(R.string.app_name), when);
try {
if (notification != null) {
notification.contentView = simpleContentView;
notification.contentIntent = pendingIntent;
if (currentVersionSupportBigNotification()) {
notification.bigContentView = expandedView;
}
notification.contentView.setTextViewText(R.id.txt_title_notification, title);
notification.contentView.setTextViewText(R.id.txt_desc_notification, description);
if (image != null && !image.equals("")) {
try {
notification.contentView.setImageViewBitmap(R.id.img_poster_notification, bitmap);
} catch (Exception e) {
e.printStackTrace();
}
} else {
notification.contentView.setImageViewResource(R.id.img_poster_notification, R.drawable.placeholder_144x214);
}
if (currentVersionSupportBigNotification()) {
notification.bigContentView.setTextViewText(R.id.txt_title_notification, title);
notification.bigContentView.setTextViewText(R.id.txt_desc_notification, description);
if (image != null && !image.equals("")) {
try {
notification.bigContentView.setImageViewBitmap(R.id.img_poster_notification, bitmap);
} catch (Exception e) {
e.printStackTrace();
}
} else {
notification.bigContentView.setImageViewResource(R.id.img_poster_notification, R.drawable.placeholder_144x214);
}
}
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;//Vibration
notification.defaults |= Notification.DEFAULT_SOUND;
mNotifyManager = (NotificationManager) getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
mNotifyManager.notify(NOTIFICATION_ID, notification);
}
} catch (Exception e) {
e.printStackTrace();
GlobalApp.Log("Notification_exc", "" + e.getMessage());
}
}
使用
setImageViewResource
instanceofsetImageViewBitmap
我无法使用此方法,因为我使用从服务器加载的不同位图。好的,请检查下面的代码这是否有效。我尝试了此方法,但不起作用。我还尝试使用setImageViewResource()将图像设置为资源,它可以工作,但无法使用位图