Android O Notification Building Fix (#655)

-Added simple notification channel for Android O.
-Fixes notification building failure for background and popup player on Android O.
-Reduce notification channel importance to low to avoid making noise on every notification update.
This commit is contained in:
Tonelico 2017-08-18 05:05:31 -07:00 committed by Mauricio Colli
parent 9fbac943bb
commit 85108be686
4 changed files with 34 additions and 4 deletions

View file

@ -1,7 +1,10 @@
package org.schabi.newpipe;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import com.facebook.stetho.Stetho;
import com.nostra13.universalimageloader.core.ImageLoader;
@ -89,6 +92,8 @@ public class App extends Application {
SettingsActivity.initSettings(this);
ThemeHelper.setTheme(getApplicationContext());
initNotificationChannel();
}
/**
@ -112,4 +117,23 @@ public class App extends Application {
public static boolean isUsingTor() {
return useTor;
}
public void initNotificationChannel() {
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
return;
}
final String id = getString(R.string.notification_channel_id);
final CharSequence name = getString(R.string.notification_channel_name);
final String description = getString(R.string.notification_channel_description);
// Keep this below DEFAULT to avoid making noise on every notification update
final int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel);
}
}