Стиль и приоретет уведомления
Сверху уведомление которое мне нужно, снизу которое получилось сделать у меня
Мне нужно также чтобы загружаемая картинка была слева а иконка приложения вставала в левый нижний угол картинки, также я не могу понять как сделать уведомление выше ведь присутствует какая-то разделяющая точка
прикладываю код:
public static void createNotificationChannel(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "name";
String description = "desk";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(MainActivity.CHANNEL_ID, name, importance);
channel.setDescription(description);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
}
}
public static void createNotificationBtn(Context context, int notificationId, String imageUrl) {
Intent buttonIntent = new Intent(context, NotificationReceiver.class);
buttonIntent.setAction(ACTION);
buttonIntent.putExtra(MainActivity.EXTRA_NOTIFICATION_ID, notificationId);
PendingIntent buttonPendingIntent = PendingIntent.getBroadcast(context, notificationId, buttonIntent, PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MainActivity.CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("привет")
.setContentText("ещё привет")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_NAVIGATION)
.addAction(R.mipmap.ic_launcher, ACTION, buttonPendingIntent);
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... voids) {
try {
URL url = new URL(imageUrl);
return BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException ignored) {}
return null;
}
@SuppressLint("RestrictedApi")
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
builder.setLargeIcon(bitmap);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((MainActivity) context, new String[]{android.Manifest.permission.POST_NOTIFICATIONS}, 1);
}
notificationManager.notify(notificationId, builder.build());
}
}
}.execute();
}
