Skip to content

Commit

Permalink
Support for notification channels introduced in Oreo
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloyan-raev committed Feb 9, 2018
1 parent 07b9b8c commit 3328f02
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void doDownload() {
Snackbar.LENGTH_LONG).show();
// init the download notification
mNotifyManager = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(mActivity)
mBuilder = new NotificationCompat.Builder(mActivity, FileTransferChannel.ID)
.setSmallIcon(android.R.drawable.stat_sys_download)
.setColor(ContextCompat.getColor(mActivity, R.color.colorNotification))
.setContentTitle(mFile.getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2018 Kaloyan Raev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package name.raev.kaloyan.hellostorj;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;

import android.os.Build;

public class FileTransferChannel {

public static final String ID = "file_transfer";

public static void create(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
// The user-visible name of the channel.
CharSequence name = context.getString(R.string.channel_name);
// The user-visible description of the channel.
String description = context.getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new android.app.NotificationChannel(ID, name, importance);
// Configure the notification channel.
channel.setDescription(description);
channel.enableLights(false);
channel.enableVibration(false);
notificationManager.createNotificationChannel(channel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void upload() {
Snackbar.LENGTH_LONG).show();
// init the upload notification
mNotifyManager = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(mActivity)
mBuilder = new NotificationCompat.Builder(mActivity, FileTransferChannel.ID)
.setSmallIcon(android.R.drawable.stat_sys_upload)
.setColor(ContextCompat.getColor(mActivity, R.color.colorNotification))
.setContentTitle(new java.io.File(mFilePath).getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Kaloyan Raev
* Copyright (C) 2017-2018 Kaloyan Raev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,6 +47,8 @@ protected void onCreate(Bundle savedInstanceState) {
View recyclerView = findViewById(R.id.main_list);
assert recyclerView != null;
setupRecyclerView((RecyclerView) recyclerView);

FileTransferChannel.create(this);
}

private void setupRecyclerView(@NonNull RecyclerView recyclerView) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
<string name="upload_permission_denied">Read permission denied. Upload not possible.</string>
<string name="upload_not_supported">Document provider not supported. Upload not possible.</string>
<string name="register_confirmation_sent">Successfully registered %1$s, please check your email to confirm.</string>
<string name="channel_name">File Transfer</string>
<string name="channel_description">Notifications for downloading and uploading files</string>
</resources>

0 comments on commit 3328f02

Please sign in to comment.