在华为设备中,如何申请banner通知权限,他默认是关闭的
我做了如下设置,只有手动开启banner通知才有效
如何解决?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "007";
String channelName = "James Bond";
NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_MAX);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
Intent notificationIntent = new Intent();
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplication(), 0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(MainActivity.this, "007")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContentTitle("What is 5G ?")
.setContentText("But before we get to the smart phones, let's simply figure out what 5G is.")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher_background)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background))
.setDefaults(Notification.DEFAULT_VIBRATE)
.setAutoCancel(true)
.setVibrate(new long[0])
//.setFullScreenIntent(pendingIntent, true)
.build();
notificationManager.notify(1, notification);
}
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />