mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-04-28 01:56:12 +00:00
90 lines
3.1 KiB
Java
90 lines
3.1 KiB
Java
package com.meshchatx;
|
|
|
|
import android.app.Application;
|
|
import android.app.Notification;
|
|
import android.app.NotificationChannel;
|
|
import android.app.NotificationManager;
|
|
import android.content.Context;
|
|
import android.media.AudioAttributes;
|
|
import android.media.RingtoneManager;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.provider.Settings;
|
|
|
|
import com.chaquo.python.android.PyApplication;
|
|
|
|
public class MeshChatApplication extends PyApplication {
|
|
public static final String CHANNEL_ID_MESSAGES = "meshchatx_messages";
|
|
public static final String CHANNEL_ID_BACKGROUND = "meshchatx_background";
|
|
public static final String CHANNEL_ID_CALLS = "meshchatx_calls";
|
|
|
|
private static volatile Context appContext;
|
|
|
|
public static Context getAppContext() {
|
|
return appContext;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
appContext = getApplicationContext();
|
|
createNotificationChannels();
|
|
}
|
|
|
|
private void createNotificationChannels() {
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
return;
|
|
}
|
|
NotificationManager nm = getSystemService(NotificationManager.class);
|
|
if (nm == null) {
|
|
return;
|
|
}
|
|
|
|
NotificationChannel background = new NotificationChannel(
|
|
CHANNEL_ID_BACKGROUND,
|
|
getString(R.string.notification_channel_background_name),
|
|
NotificationManager.IMPORTANCE_LOW
|
|
);
|
|
background.setDescription(getString(R.string.notification_channel_background_desc));
|
|
nm.createNotificationChannel(background);
|
|
|
|
NotificationChannel messages = new NotificationChannel(
|
|
CHANNEL_ID_MESSAGES,
|
|
getString(R.string.notification_channel_messages_name),
|
|
NotificationManager.IMPORTANCE_DEFAULT
|
|
);
|
|
messages.setDescription(getString(R.string.notification_channel_messages_desc));
|
|
nm.createNotificationChannel(messages);
|
|
|
|
Uri ringUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
|
|
if (ringUri == null) {
|
|
ringUri = Settings.System.DEFAULT_RINGTONE_URI;
|
|
}
|
|
NotificationChannel calls = new NotificationChannel(
|
|
CHANNEL_ID_CALLS,
|
|
getString(R.string.notification_channel_calls_name),
|
|
NotificationManager.IMPORTANCE_HIGH
|
|
);
|
|
calls.setDescription(getString(R.string.notification_channel_calls_desc));
|
|
calls.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
calls.setBypassDnd(true);
|
|
}
|
|
if (ringUri != null) {
|
|
calls.setSound(
|
|
ringUri,
|
|
new AudioAttributes.Builder()
|
|
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
|
|
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
|
.build()
|
|
);
|
|
}
|
|
long[] pattern = new long[] {0, 400, 200, 400, 200, 600};
|
|
try {
|
|
calls.setVibrationPattern(pattern);
|
|
} catch (Exception ignored) {
|
|
}
|
|
nm.createNotificationChannel(calls);
|
|
}
|
|
}
|