|
|
|
@ -1,14 +1,22 @@
|
|
|
|
|
package eu.droogers.smsmatrix;
|
|
|
|
|
|
|
|
|
|
import android.app.Notification;
|
|
|
|
|
import android.app.NotificationChannel;
|
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
|
import android.app.Service;
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.IBinder;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by gerben on 7-10-17.
|
|
|
|
|
*/
|
|
|
|
@ -24,6 +32,7 @@ public class MatrixService extends Service {
|
|
|
|
|
private String syncDelay;
|
|
|
|
|
private String syncTimeout;
|
|
|
|
|
private MMSMonitor mms;
|
|
|
|
|
private String mChannelId = "";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
@ -32,6 +41,21 @@ public class MatrixService extends Service {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
|
|
|
|
if (mChannelId.isEmpty()) {
|
|
|
|
|
mChannelId = createNotificationChannel("sync", "Sync Service");
|
|
|
|
|
}
|
|
|
|
|
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, mChannelId);
|
|
|
|
|
Notification notification = notificationBuilder.setOngoing(true)
|
|
|
|
|
.setSmallIcon(R.mipmap.ic_launcher)
|
|
|
|
|
.setContentText(getApplicationInfo().loadLabel(getPackageManager()))
|
|
|
|
|
.setPriority(NotificationCompat.PRIORITY_MIN)
|
|
|
|
|
.setCategory(Notification.CATEGORY_SERVICE)
|
|
|
|
|
.build();
|
|
|
|
|
startForeground(1, notification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SharedPreferences sp = getSharedPreferences("settings", Context.MODE_PRIVATE);
|
|
|
|
|
botUsername = sp.getString("botUsername", "");
|
|
|
|
|
botPassword = sp.getString("botPassword", "");
|
|
|
|
@ -76,6 +100,17 @@ public class MatrixService extends Service {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
|
|
private String createNotificationChannel(String channelId, String channelName){
|
|
|
|
|
NotificationChannel chan = new NotificationChannel(channelId,
|
|
|
|
|
channelName, NotificationManager.IMPORTANCE_NONE);
|
|
|
|
|
chan.setLightColor(Color.BLUE);
|
|
|
|
|
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
|
|
|
|
NotificationManager service = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
service.createNotificationChannel(chan);
|
|
|
|
|
return channelId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDestroy() {
|
|
|
|
|
mx.destroy();
|
|
|
|
|