Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notification channels #1059

Merged
merged 1 commit into from Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />

<application
android:name=".App"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/ru/meefik/linuxdeploy/ActionReceiver.java
Expand Up @@ -7,6 +7,8 @@

import androidx.core.app.NotificationCompat;

import static ru.meefik.linuxdeploy.App.SERVICE_CHANNEL_ID;

public class ActionReceiver extends BroadcastReceiver {

final static int NOTIFY_ID = 2;
Expand All @@ -16,7 +18,7 @@ public class ActionReceiver extends BroadcastReceiver {
private void showNotification(Context c, int icon, String text) {
NotificationManager mNotificationManager = (NotificationManager) c
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c, SERVICE_CHANNEL_ID)
.setSmallIcon(icon)
.setContentTitle(c.getString(R.string.app_name))
.setContentText(text);
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/ru/meefik/linuxdeploy/App.java
@@ -0,0 +1,36 @@
package ru.meefik.linuxdeploy;

import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;

public class App extends Application {

public static final String SERVICE_CHANNEL_ID = "SERVICE_CHANNEL";

@Override
public void onCreate() {
super.onCreate();

// Create notification channels for Oreo and newer
createNotificationChannels();
}

private void createNotificationChannels() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.service_notification_channel_name);
String description = getString(R.string.service_notification_channel_description);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel channel = new NotificationChannel(SERVICE_CHANNEL_ID, name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}

}
}
4 changes: 3 additions & 1 deletion app/src/main/java/ru/meefik/linuxdeploy/PrefStore.java
Expand Up @@ -24,6 +24,8 @@
import androidx.core.app.NotificationCompat;
import androidx.core.app.TaskStackBuilder;

import static ru.meefik.linuxdeploy.App.SERVICE_CHANNEL_ID;

public class PrefStore {

private final static SettingsStore SETTINGS = new SettingsStore();
Expand Down Expand Up @@ -774,7 +776,7 @@ static void showNotification(Context context, Intent intent) {
.getSystemService(Context.NOTIFICATION_SERVICE);
if (isNotification(context)) {
setLocale(context);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, SERVICE_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.notification_current_profile)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -352,5 +352,7 @@
<string name="help_text">\n<b>Help</b>\n\nThis application installs the selected GNU/Linux distribution and executes it in a chroot-container.\n\nProcedure:\n1. Get superuser privileges (root).\n2. Check the connection to Internet.\n3. Specify the installation options.\n4. Start the installation (\"Menu => Install\").\n5. Wait until the installation is complete.\n6. Tap \"START\" button to run the container.\n7. Connect to the container through CLI, SSH, VNC, or others.\n\nFor more information, see \"About\".</string>
<!-- ABOUT -->
<string name="about_text">This application installs the selected GNU/Linux distribution and executes it in a chroot-container.\n\nFor more information see <a href="https://github.com/meefik/linuxdeploy">project page</a>, <a href="http://4pda.ru/forum/index.php?showtopic=378043">forum</a> or <a href="http://meefik.ru">developer site</a>.\n\n&#169; 2012&#8211;2018 Anton Skshidlevsky, GPLv3</string>
<string name="service_notification_channel_description">Channel to display service notifications.</string>
<string name="service_notification_channel_name">Services</string>

</resources>