android - 我想在我的通知中添加一个大图标,但是当我运行应用程序时,大图标没有显示。下面是我的代码,有什么不对的地方吗?

标签 android notifications

我想创建带有大图标和小图标的通知,但显示的通知只有小图标、标题和子标题!

如果有人能帮助我,我将不胜感激。 我编写这些代码来创建通知

public class MainActivity extends AppCompatActivity {
private EditText editTitle, editSubTitle;
private Button btn_send_simple;
private NotificationCompat.Builder builder;
private NotificationManagerCompat nmc;
private Notification notification;
private Bitmap largeIcon;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editTitle = findViewById(R.id.edit_title);
    editSubTitle = findViewById(R.id.edit_sub_title);
    largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_sport);
    builder = new NotificationCompat.Builder(this, "");
    builder.setLargeIcon(largeIcon)
            .setSmallIcon(R.drawable.ic_call)
            .setContentTitle(editTitle.getText().toString())
            .setContentText(editSubTitle.getText().toString())
    ;
    nmc = NotificationManagerCompat.from(this);
    notification = builder.build();
}

public void sendSimpleNotif(View view) {
    builder.setLargeIcon(largeIcon)
            .setSmallIcon(R.drawable.ic_call)
            .setContentTitle(editTitle.getText().toString())
            .setContentText(editSubTitle.getText().toString()) ;

    notification = builder.build();
    nmc = NotificationManagerCompat.from(this);
    nmc.notify(500, notification);
}

最佳答案

对于通知中的大图标试试这个:

Notification notification = new     

NotificationCompat.Builder(context,                          

 CHANNEL_ID)
 .setSmallIcon(R.drawable.new_post)      .setContentTitle(imageTitle)
 .setContentText(imageDescription)
 .setStyle(new                        

 NotificationCompat
 .BigPictureStyle()
  .bigPicture(myBitmap))
 .build();

在这里将您的图标作为位图传递。 如需更多帮助,请尝试此链接 https://developer.android.com/training/notify-user/expanded#java

关于android - 我想在我的通知中添加一个大图标,但是当我运行应用程序时,大图标没有显示。下面是我的代码,有什么不对的地方吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58293037/

相关文章:

java - Android 中无需登录的 Firebase OTP 验证

android - android什么时候会在没有唤醒锁的情况下停止它的cpu?

android - 相对布局 : layout_marginLeft inconsistent behaviour

java - 信号服务器错误 : org. glassfish.jersey.message.internal.MessageBodyProviderNotFoundException

到达位置时iOS本地通知

android - 在Windows 10和VS2015 Android模拟器上运行时,Android App崩溃

Android BroadcastReceiver 设置闹钟

api - 如何使用 JEST 模拟通知 API?

javascript - 如何在 Web 应用程序中显示通知?

notifications - 删除 Redis 中 Sets 类型的最后一项