Search in sources :

Example 11 with NotificationChannel

use of android.app.NotificationChannel in project bitcoin-wallet by bitcoin-wallet.

the class WalletApplication method initNotificationManager.

private void initNotificationManager() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final Stopwatch watch = Stopwatch.createStarted();
        final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        final NotificationChannel received = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_RECEIVED, getString(R.string.notification_channel_received_name), NotificationManager.IMPORTANCE_DEFAULT);
        received.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received), new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setLegacyStreamType(AudioManager.STREAM_NOTIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build());
        nm.createNotificationChannel(received);
        final NotificationChannel ongoing = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_ONGOING, getString(R.string.notification_channel_ongoing_name), NotificationManager.IMPORTANCE_LOW);
        nm.createNotificationChannel(ongoing);
        final NotificationChannel important = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_IMPORTANT, getString(R.string.notification_channel_important_name), NotificationManager.IMPORTANCE_HIGH);
        nm.createNotificationChannel(important);
        log.info("created notification channels, took {}", watch);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) Stopwatch(com.google.common.base.Stopwatch) AudioAttributes(android.media.AudioAttributes)

Example 12 with NotificationChannel

use of android.app.NotificationChannel in project aware-client by denzilferreira.

the class Aware method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    AUTHORITY = Aware_Provider.getAuthority(this);
    IntentFilter storage = new IntentFilter();
    storage.addAction(Intent.ACTION_MEDIA_MOUNTED);
    storage.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
    storage.addDataScheme("file");
    registerReceiver(storage_BR, storage);
    IntentFilter boot = new IntentFilter();
    boot.addAction(Intent.ACTION_BOOT_COMPLETED);
    boot.addAction(Intent.ACTION_SHUTDOWN);
    boot.addAction(Intent.ACTION_REBOOT);
    boot.addAction(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(awareBoot, boot);
    IntentFilter awareActions = new IntentFilter();
    awareActions.addAction(Aware.ACTION_AWARE_SYNC_DATA);
    awareActions.addAction(Aware.ACTION_QUIT_STUDY);
    registerReceiver(aware_BR, awareActions);
    IntentFilter foreground = new IntentFilter();
    foreground.addAction(Aware.ACTION_AWARE_PRIORITY_FOREGROUND);
    foreground.addAction(Aware.ACTION_AWARE_PRIORITY_BACKGROUND);
    registerReceiver(foregroundMgr, foreground);
    IntentFilter scheduler = new IntentFilter();
    scheduler.addAction(Intent.ACTION_TIME_TICK);
    schedulerTicker.interval_ms = 60000 * getApplicationContext().getResources().getInteger(R.integer.alarm_wakeup_interval_min);
    registerReceiver(schedulerTicker, scheduler);
    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        stopSelf();
        return;
    }
    // Android 8 specific: create a notification channel for AWARE
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager not_manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        NotificationChannel aware_channel = new NotificationChannel(AWARE_NOTIFICATION_ID, getResources().getString(R.string.app_name), NotificationManager.IMPORTANCE_DEFAULT);
        aware_channel.setDescription(getResources().getString(R.string.aware_description));
        aware_channel.enableLights(true);
        aware_channel.setLightColor(Color.BLUE);
        aware_channel.enableVibration(true);
        not_manager.createNotificationChannel(aware_channel);
    }
    // Start the foreground service only if it's the client or a standalone application
    if ((getApplicationContext().getPackageName().equals("com.aware.phone") || getApplicationContext().getApplicationContext().getResources().getBoolean(R.bool.standalone)))
        getApplicationContext().sendBroadcast(new Intent(Aware.ACTION_AWARE_PRIORITY_FOREGROUND));
    if (Aware.DEBUG)
        Log.d(TAG, "AWARE framework is created!");
    IS_CORE_RUNNING = true;
    aware_account = getAWAREAccount(this);
}
Also used : NotificationChannel(android.app.NotificationChannel) IntentFilter(android.content.IntentFilter) NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

NotificationChannel (android.app.NotificationChannel)12 NotificationManager (android.app.NotificationManager)8 Intent (android.content.Intent)4 RequiresApi (android.support.annotation.RequiresApi)4 PendingIntent (android.app.PendingIntent)3 SuppressLint (android.annotation.SuppressLint)2 Notification (android.app.Notification)2 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Sensor (android.hardware.Sensor)1 SensorManager (android.hardware.SensorManager)1 AudioAttributes (android.media.AudioAttributes)1 AppConfiguration (com.github.moko256.twicalico.config.AppConfiguration)1 TokenSQLiteOpenHelper (com.github.moko256.twicalico.database.TokenSQLiteOpenHelper)1 AccessToken (com.github.moko256.twicalico.entity.AccessToken)1 ExceptionNotification (com.github.moko256.twicalico.notification.ExceptionNotification)1 Stopwatch (com.google.common.base.Stopwatch)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1