gpt4 book ai didi

android - RemoteViews setImageViewBitmap() 不工作

转载 作者:行者123 更新时间:2023-12-05 08:08:15 26 4
gpt4 key购买 nike

我正在开发一个带有自定义通知布局的简单 Android 应用程序。为此,我使用了 RemoteViews。我的布局中有一个 ImageView,但我无法为其设置位图。

我使用这段代码来设置位图:

layout.setImageViewBitmap(R.id.noteNotificationImage, bitmap)

我也尝试过使用 Canvas ,但这对我没有帮助:

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)

位图不为空,当我在简单的布局中使用它时一切正常,而不是在 RemoteViews 中。

谁能帮帮我?

最佳答案

我不知道问题出在哪里,但这段代码对我来说工作正常

    @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());
}
}

关于android - RemoteViews setImageViewBitmap() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50597183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com