Commit bbdaea41 authored by wanglei's avatar wanglei

...

parent 4592181e
......@@ -187,9 +187,42 @@
android:resource="@xml/file_paths" />
</provider>
<!-- <service-->
<!-- android:name=".service.StayNotificationService"-->
<!-- android:foregroundServiceType="dataSync" />-->
<service
android:name=".service.StayJobService"
android:exported="false"
android:foregroundServiceType="dataSync"
android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver
android:name=".fcm.alarm.AlarmJobReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_EJECT" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file" />
</intent-filter>
</receiver>
<service
android:name=".fcm.MessagingService"
android:exported="false">
......@@ -198,12 +231,6 @@
</intent-filter>
</service>
<service
android:name=".service.StayJobService"
android:exported="false"
android:foregroundServiceType="dataSync"
android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver
android:name=".fcm.FcmReceiver"
android:directBootAware="true"
......@@ -217,12 +244,14 @@
</intent-filter>
</receiver>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
</application>
</manifest>
\ No newline at end of file
......@@ -4,12 +4,19 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.base.pdfviewerscannerwhite.helper.EventUtils;
import com.base.pdfviewerscannerwhite.utils.LogEx;
public class FcmReceiver extends BroadcastReceiver {
private String TAG = "FcmReceiver";
@Override
public void onReceive(Context context, Intent intent) {
LogEx.INSTANCE.logDebug(TAG, "onReceive", false);
NotificationUiUtil.INSTANCE.sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_FCM, null);
EventUtils.INSTANCE.event("FCM_Received", "FcmReceiver", null, false);
}
}
......@@ -2,12 +2,17 @@ package com.base.pdfviewerscannerwhite.fcm;
import android.annotation.SuppressLint;
import androidx.annotation.NonNull;
import com.base.pdfviewerscannerwhite.helper.EventUtils;
import com.base.pdfviewerscannerwhite.utils.LogEx;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import org.json.JSONException;
import org.json.JSONObject;
@SuppressLint("MissingFirebaseInstanceTokenRefresh")
public class MessagingService extends FirebaseMessagingService {
......@@ -17,10 +22,28 @@ public class MessagingService extends FirebaseMessagingService {
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
LogEx.INSTANCE.logDebug(TAG, "onMessageReceived", false);
EventUtils.INSTANCE.event("FCM_Received", null, null, false);
String action = NotificationUiUtil.INSTANCE.getNextActionId();
NotificationUiUtil.INSTANCE.sendNotificationIfCan(this, action, PopupConstObject.POPUP_WHERE_FCM);
String id = remoteMessage.getMessageId();
JSONObject ext = new JSONObject();
try {
ext.put("type", "MessagingService");
ext.put("getMessageType", remoteMessage.getMessageType());
ext.put("getData", remoteMessage.getData());
ext.put("getCollapseKey", remoteMessage.getCollapseKey());
ext.put("getFrom", remoteMessage.getFrom());
ext.put("getPriority", remoteMessage.getPriority());
ext.put("getSenderId", remoteMessage.getSenderId());
ext.put("getSentTime", remoteMessage.getSentTime());
} catch (JSONException e) {
EventUtils.INSTANCE.event("FCM_Received_Error", id, ext, false);
throw new RuntimeException(e);
} finally {
}
EventUtils.INSTANCE.event("FCM_Received", id, ext, false);
}
......
......@@ -7,6 +7,7 @@ object PopupConstObject {
const val POPUP_WHERE_TIMBER = "Timer"
const val POPUP_WHERE_LOCK = "Lock"
const val POPUP_WHERE_FCM = "fcm"
const val POPUP_WHERE_ALARM = "Alarm"
const val POPUP_WHERE_WORK_MANAGER = "workmanager"
const val POPUP_WHERE_MEDIA_CHANGE = "media_change"
const val POPUP_WHERE_HOVER_HANDLE = "hover_handle"//悬停调用
......
package com.base.pdfviewerscannerwhite.fcm.alarm
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.base.pdfviewerscannerwhite.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.pdfviewerscannerwhite.fcm.PopupConstObject
import com.base.pdfviewerscannerwhite.helper.EventUtils
import com.base.pdfviewerscannerwhite.utils.AppPreferences
import com.base.pdfviewerscannerwhite.utils.LogEx
class AlarmJobReceiver : BroadcastReceiver() {
private val TAG = "AlarmJobReceiver"
@SuppressLint("UnsafeProtectedBroadcastReceiver")
override fun onReceive(context: Context, intent: Intent?) {
LogEx.logDebug(TAG, "AlarmJobReceiver onReceive")
EventUtils.event("alarm_push")
val lastAlarmTime = AppPreferences.getInstance().getLong("lastAlarmTime", 0L)
val currentTime = System.currentTimeMillis()
if (lastAlarmTime == 0L || currentTime - lastAlarmTime >= 1000 * 30 * 60) {
sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_ALARM)
AppPreferences.getInstance().put("lastAlarmTime", System.currentTimeMillis())
}
return
}
}
\ No newline at end of file
package com.base.pdfviewerscannerwhite.fcm.alarm
import android.app.AlarmManager
import android.app.PendingIntent
import android.app.job.JobService
import android.content.Context
import android.content.Intent
import com.base.pdfviewerscannerwhite.BuildConfig
import com.base.pdfviewerscannerwhite.fcm.work.schedulePeriodicWork
import com.base.pdfviewerscannerwhite.service.StayJobService.Companion.startJob
import java.util.Calendar
object AlarmUtils {
fun startAlarm(context: Context) {
context.startJob()
//闹钟定时任务
val alarmManager = context.getSystemService(JobService.ALARM_SERVICE) as AlarmManager
val pendingIntent = PendingIntent.getBroadcast(
context, 1, Intent(context, AlarmJobReceiver::class.java),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 6)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
var delay = 1800000L
if (BuildConfig.DEBUG) {
delay = 1 * 60 * 1000L
}
alarmManager.setRepeating(
AlarmManager.RTC_WAKEUP, calendar.timeInMillis, delay, pendingIntent
)
schedulePeriodicWork(context)
}
}
\ No newline at end of file
package com.base.pdfviewerscannerwhite.work
package com.base.pdfviewerscannerwhite.fcm.work
import android.content.Context
import androidx.work.Constraints
......
......@@ -7,9 +7,9 @@ import android.os.Bundle
import android.text.TextUtils
import com.base.pdfviewerscannerwhite.BuildConfig
import com.base.pdfviewerscannerwhite.fcm.FCMManager
import com.base.pdfviewerscannerwhite.fcm.FCMManager.getToken
import com.base.pdfviewerscannerwhite.fcm.PopupConstObject.topic_number
import com.base.pdfviewerscannerwhite.fcm.ScreenStatusReceiver
import com.base.pdfviewerscannerwhite.fcm.alarm.AlarmUtils.startAlarm
import com.base.pdfviewerscannerwhite.helper.WeatherUtils.requestWeatherData
import com.base.pdfviewerscannerwhite.service.StayJobService.Companion.startJob
import com.base.pdfviewerscannerwhite.ui.splash.SplashActivity
......@@ -17,7 +17,7 @@ import com.base.pdfviewerscannerwhite.utils.ActivityManagerUtils
import com.base.pdfviewerscannerwhite.utils.AppPreferences
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatMinute
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.work.schedulePeriodicWork
import com.base.pdfviewerscannerwhite.fcm.work.schedulePeriodicWork
import com.facebook.FacebookSdk
import com.reyun.solar.engine.OnAttributionListener
import com.reyun.solar.engine.OnInitializationCallback
......@@ -98,7 +98,9 @@ class MyApplication : Application() {
InstallHelps.init()
initLifeListener()
ScreenStatusReceiver.setupScreenStatusListener(this)
startJob()
startAlarm(context)
}
fun initSolarEngine(gdprDeny: Boolean = false) {
......
......@@ -48,7 +48,6 @@ object PdfBoxUtils {
val bitmap: Bitmap = renderer.renderImage(pageIndex, scale, ImageType.RGB, RenderDestination.EXPORT)
val drawable = BitmapDrawable(context.resources, bitmap)
document.close()
return drawable
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment