|
@@ -1,10 +1,17 @@
|
|
|
package com.usai.redant.raimage;
|
|
package com.usai.redant.raimage;
|
|
|
|
|
|
|
|
|
|
+import static android.app.PendingIntent.FLAG_IMMUTABLE;
|
|
|
|
|
+
|
|
|
import android.app.AlarmManager;
|
|
import android.app.AlarmManager;
|
|
|
|
|
+import android.app.Notification;
|
|
|
|
|
+import android.app.NotificationChannel;
|
|
|
|
|
+import android.app.NotificationManager;
|
|
|
import android.app.PendingIntent;
|
|
import android.app.PendingIntent;
|
|
|
|
|
+import android.content.BroadcastReceiver;
|
|
|
import android.content.ComponentName;
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
|
|
+import android.content.IntentFilter;
|
|
|
import android.content.ServiceConnection;
|
|
import android.content.ServiceConnection;
|
|
|
import android.content.SharedPreferences;
|
|
import android.content.SharedPreferences;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
@@ -14,7 +21,10 @@ import android.provider.Settings;
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
+import androidx.core.app.NotificationCompat;
|
|
|
|
|
+
|
|
|
import com.usai.redant.rautils.application.RedantApplication;
|
|
import com.usai.redant.rautils.application.RedantApplication;
|
|
|
|
|
+import com.usai.redant.rautils.upload.TaskActivity;
|
|
|
import com.usai.redant.rautils.utils.RACrashHandler;
|
|
import com.usai.redant.rautils.utils.RACrashHandler;
|
|
|
import com.usai.service.RAImageBackgroundService3;
|
|
import com.usai.service.RAImageBackgroundService3;
|
|
|
|
|
|
|
@@ -24,6 +34,8 @@ import java.util.concurrent.locks.Lock;
|
|
|
import java.util.concurrent.locks.ReadWriteLock;
|
|
import java.util.concurrent.locks.ReadWriteLock;
|
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
|
|
|
|
|
|
|
+import kotlinx.coroutines.scheduling.Task;
|
|
|
|
|
+
|
|
|
public class RAImageApplication extends RedantApplication
|
|
public class RAImageApplication extends RedantApplication
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -47,7 +59,69 @@ public class RAImageApplication extends RedantApplication
|
|
|
|
|
|
|
|
// public static RedAntApplication getInstance() {
|
|
// public static RedAntApplication getInstance() {
|
|
|
// return instance;
|
|
// return instance;
|
|
|
-// }
|
|
|
|
|
|
|
+//
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private final BroadcastReceiver ApplicaitonReceiver = new BroadcastReceiver()
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ public void onReceive(
|
|
|
|
|
+ Context context,
|
|
|
|
|
+ Intent intent)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ int count = intent.getIntExtra("count",-1);
|
|
|
|
|
+
|
|
|
|
|
+ String action = intent
|
|
|
|
|
+ .getAction();
|
|
|
|
|
+ if ("REDANT.RAImage.UPLOAD_UPDATE_COUNT".equals(action))
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ TaskActivity t;
|
|
|
|
|
+ PendingIntent contentIntent=PendingIntent.getActivity(getApplicationContext(),
|
|
|
|
|
+ 0,new Intent(getApplicationContext(), TaskActivity.class),FLAG_IMMUTABLE);
|
|
|
|
|
+ if (count>0)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+// new Intent(getApplicationContext(), TaskActivity.class);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+// new Intent (getApplicationContext(),TaskActivity.class);
|
|
|
|
|
+ NotificationChannel channel = new NotificationChannel("Service Start",
|
|
|
|
|
+ "Service Start", NotificationManager.IMPORTANCE_HIGH);
|
|
|
|
|
+ ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
|
|
|
|
|
+
|
|
|
|
|
+ Notification notification = new NotificationCompat.Builder(mService, "Service Start")
|
|
|
|
|
+// .setContentTitle("Apex Land is running.")
|
|
|
|
|
+ .setContentText(count + " files uploading...")
|
|
|
|
|
+ .setContentIntent(contentIntent)
|
|
|
|
|
+ .setCategory(Notification.CATEGORY_SERVICE).setSmallIcon(com.usai.redant.rautils.R.drawable.ic_launcher_foreground).setPriority(1000).build();
|
|
|
|
|
+ mService.startForeground(101, notification);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ if(count==0)
|
|
|
|
|
+ {
|
|
|
|
|
+ NotificationChannel channel = new NotificationChannel("Service Start",
|
|
|
|
|
+ "Service Start", NotificationManager.IMPORTANCE_HIGH);
|
|
|
|
|
+ ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
|
|
|
|
|
+
|
|
|
|
|
+ Notification notification = new NotificationCompat.Builder(mService, "Service Start")
|
|
|
|
|
+// .setContentTitle("Apex Land is running.")
|
|
|
|
|
+ .setContentText("Upload complete.")
|
|
|
|
|
+ .setContentIntent(contentIntent)
|
|
|
|
|
+ .setCategory(Notification.CATEGORY_SERVICE).setSmallIcon(com.usai.redant.rautils.R.drawable.ic_launcher_foreground).setPriority(1000).build();
|
|
|
|
|
+
|
|
|
|
|
+ mService.startForeground(101, notification);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+//
|
|
|
|
|
+ Log.e("Finish_msg", "Application onReceive: ");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
public static void startalarm()
|
|
public static void startalarm()
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -90,6 +164,21 @@ public class RAImageApplication extends RedantApplication
|
|
|
Log.d("_RAIMAGE", "onCreate: RedAntApplication");
|
|
Log.d("_RAIMAGE", "onCreate: RedAntApplication");
|
|
|
super.onCreate();
|
|
super.onCreate();
|
|
|
|
|
|
|
|
|
|
+ IntentFilter msgFilter = new IntentFilter();
|
|
|
|
|
+ msgFilter.addAction("REDANT.RAImage.UPLOAD_UPDATE_COUNT");
|
|
|
|
|
+
|
|
|
|
|
+ msgFilter.setPriority(2147483647);
|
|
|
|
|
+
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
|
|
|
|
+ {
|
|
|
|
|
+ registerReceiver(ApplicaitonReceiver, msgFilter,RECEIVER_NOT_EXPORTED);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ registerReceiver(ApplicaitonReceiver, msgFilter);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// setInstance(this);
|
|
// setInstance(this);
|
|
|
//instance = this;
|
|
//instance = this;
|
|
|
|
|
|
|
@@ -159,6 +248,9 @@ public class RAImageApplication extends RedantApplication
|
|
|
super.onTerminate();
|
|
super.onTerminate();
|
|
|
|
|
|
|
|
unbindService(mServiceConnection);
|
|
unbindService(mServiceConnection);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ unregisterReceiver(ApplicaitonReceiver);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|