У меня есть 2 функции Push Notification.
Для нуги (7.0) (не работает выше 24)
Uri SoundUri = RingtoneManager.getDefaultUri((RingtoneManager.TYPE_NOTIFICATION));
Notification notification = new Notification.Builder(first.this)
.setVibrate(new long[] { 350, 350})
.setSmallIcon(R.drawable.testicon)
.setContentTitle("test tittle")
.setContentText("test content")
.setSound(SoundUri).build();
NotificationManager notifmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notifmanager.notify(0,notification);
Для Oreo или выше + (8.0) (не работает для Nougat api 24)
CharSequence name = getString(R.string.channel_name);// The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;
String CHANNEL_ID = "my_channel_01";// The id of the channel.
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
int notifyID = 1;
Notification notification = new NotificationCompat.Builder(this)
.setVibrate(new long[] { 350, 350})
.setSmallIcon(R.drawable.testicon)
.setContentTitle("test tittle")
.setChannelId(CHANNEL_ID).build();
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel);
mNotificationManager.notify(notifyID , notification);
теперь я использую Gradle
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.test.testttt"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
есть ли Push-уведомление (метод / функция), которое принято почти во всех версиях Android (поэтому я хочу сделатьон принял по крайней мере API +17)