我想向通知添加一个大图标,但是当我运行应用时,大图标没有显示。下面是我的代码,有什么帮助吗?



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

如果有人可以帮助我,我很感激。 我编写这些代码来创建通知

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

最新更新