Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e5da77c authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Create NotificationChannel when SDK is >= Oreo

Add method to create notificationChannel in CommonUtils
and add few strings (in res/values folder) for that purpose
parent 85cd5349
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -11,9 +11,12 @@ package foundation.e.drive;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.util.Log;

@@ -43,11 +46,13 @@ public class EdriveApplication extends Application {
        mFileObserver = new RecursiveFileObserver(getApplicationContext(), pathForObserver, fileEventListener);

        SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        CommonUtils.createNotificationChannel(getApplicationContext());

        if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) {
            Log.d(TAG, "Account already registered");
            startRecursiveFileObserver();


            Intent SynchronizationServiceIntent = new Intent(getApplicationContext(), SynchronizationService.class);
            startService(SynchronizationServiceIntent);

+1 −2
Original line number Diff line number Diff line
@@ -34,8 +34,7 @@ public abstract class AppConstants {
    public static final String[] MEDIA_SYNCABLE_CATEGORIES = new String[]{"Images", "Movies", "Music", "Ringtones", "Documents", "Podcasts"};
    public static final String[] SETTINGS_SYNCABLE_CATEGORIES = new String[] {"Rom settings"};

    public static final String notificationChannelID ="3310";
    public static final String notificationChannelName="eDrive channel";
    public static final String notificationChannelID ="foundation.e.drive";
    public static final String WORK_GENERIC_TAG="eDrive";
    public static final String WORK_INITIALIZATION_TAG="eDrive-init";
    public static final String USER_AGENT = "eos("+getBuildTime()+")-eDrive("+ BuildConfig.VERSION_NAME +")";
+18 −0
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ package foundation.e.drive.utils;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
@@ -19,6 +21,7 @@ import android.media.MediaScannerConnection;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.webkit.MimeTypeMap;

@@ -35,6 +38,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;


import foundation.e.drive.R;
import foundation.e.drive.models.SyncedFolder;
import foundation.e.drive.work.CreateRemoteFolderWorker;
import foundation.e.drive.work.FirstStartWorker;
@@ -389,4 +393,18 @@ public abstract class CommonUtils {
            .putBoolean(DATA_KEY_MEDIATYPE, folder.isMediaType())
            .build();
    }

    public static void createNotificationChannel(Context context){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            final CharSequence name = context.getString(R.string.notif_channel_name);
            final String description = context.getString(R.string.notif_channel_description);
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            final NotificationChannel channel = new NotificationChannel(AppConstants.notificationChannelID, name, importance);
            channel.setDescription(description);
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            final NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }
}
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
<resources>
    <string name="app_name">/e/ Drive</string>
    <string name="eelo_account_type" translatable="false">e.foundation.webdav.eelo</string>
    <string name="notif_channel_name" translatable="false">eDrive\'s notification</string>
    <string name="notif_channel_description">eDrive\'s notification channel</string>
    <string name="notif_quota_execeeded_title">Drive Quota Exceeded</string>
    <string name="notif_channel_description">eDrive\'s notification channel</string>
</resources>