【发布时间】:2019-01-29 04:16:59
【问题描述】:
我最近对 Android Studio 进行了更新,之后我无法显示我的通知。
代码在更新之前最初运行良好,所以我认为问题出在软件而不是代码上。更新后有什么需要更改的吗?
我的程序实际上会显示一条 Toast 消息,并且还会有一条通知说帐户已注册(在注册帐户后)。但是,在 toast 消息之后,另一条 toast 消息显示“开发者警告包”com.example.jianminong.aucon”无法发布通知渠道“个人”请参阅日志以获取更多详细信息。
public void displayNotification(){
NotificationCompat.Builder builder = new
NotificationCompat.Builder(this,CHANNEL_ID);
builder.setSmallIcon(R.drawable.aucon);
builder.setContentTitle("Welcome " +
editUsername.getText().toString());
builder.setContentText("You have just created an account with
the email of " +editEmail.getText().toString());
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManagerCompat =
NotificationManagerCompat.from(this);
notificationManagerCompat.notify(NOTIFICATION_ID,builder.build());
}
private void createNotificationChannel(){
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
{
CharSequence name = "Personal";
String description = "HAHA";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID,name,importance);
notificationChannel.setDescription(description);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
}
}
【问题讨论】:
标签: android android-studio notifications android-notifications