I have a really simple Service
which triggers a notification. But it does not work.
As you probably see, all of these are just copied from the net, but I want it to work, before I tweak it.
This is called from within the service:
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String id = "my_channel_01";
CharSequence name = "someName";
String description = "even bigger name";
int importance = NotificationManager.IMPORTANCE_HIGH;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
mNotificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.big_anchor)
.setContentTitle("My notification")
.setChannel(id)
.setContentText("Hello World!");
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(getApplicationContext(),
0, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager.notify(32345, mBuilder.build());
I've read, that some parameters should be placed in AndroidManifest.xml
so also I am attaching this:
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".GpsService" />
</application>
Also, the only logs I'm receiving are:
10-30 22:44:13.939 417-417/asdf.appW/Notification: Use of stream types is deprecated for operations other than volume control
10-30 22:44:13.940 417-417/asdf.app W/Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case
Any ideas?
UPDATE
I suppose this is something related to the API version I am using. When I used API 24 everything is working. But when using Emulator with 26, nothing appears.