Commit b87f575f authored by wanglei's avatar wanglei

...

parent a2f21b05
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" /> <!-- 大致位置,依赖网络 --> <uses-permission android:name="android.permission.INTERNET" /> <!-- 大致位置,依赖网络 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 精确的位置,GPS --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- 精确的位置,GPS -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Recommended for Android 9 (API level 28) and lower. --> <!-- Recommended for Android 9 (API level 28) and lower. -->
<!-- Required for Android 10 (API level 29) and higher. --> <!-- Required for Android 10 (API level 29) and higher. -->
...@@ -19,6 +20,9 @@ ...@@ -19,6 +20,9 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application <application
android:name=".helper.MyApplication" android:name=".helper.MyApplication"
......
...@@ -91,7 +91,7 @@ class BatteryStatusReceiver() : BroadcastReceiver() { ...@@ -91,7 +91,7 @@ class BatteryStatusReceiver() : BroadcastReceiver() {
"popupBatteryCount=$popupBatteryCount where=$POPUP_WHERE_BATTERY" "popupBatteryCount=$popupBatteryCount where=$POPUP_WHERE_BATTERY"
) )
LogEx.logDebug( LogEx.logDebug(
TAG, "Notification_Error todayBatteryPush=$todayBatteryPush " + "canSendNotification", "Notification_Error todayBatteryPush=$todayBatteryPush " +
"popupBatteryCount=$popupBatteryCount where=$POPUP_WHERE_BATTERY" "popupBatteryCount=$popupBatteryCount where=$POPUP_WHERE_BATTERY"
) )
} }
......
...@@ -19,7 +19,7 @@ object NotificationHoverUtils { ...@@ -19,7 +19,7 @@ object NotificationHoverUtils {
/** /**
* 发送悬停通知 * 发送悬停通知
*/ */
fun sendHoverNotification(context: Context) { fun sendHoverNotification(context: Context, where: String = "") {
val hoverCount = AppPreferences.getInstance().getString(popup_hover_count, "0").toInt() val hoverCount = AppPreferences.getInstance().getString(popup_hover_count, "0").toInt()
val hoverDelay = AppPreferences.getInstance().getString(popup_hover_delay, "0").toLong() val hoverDelay = AppPreferences.getInstance().getString(popup_hover_delay, "0").toLong()
...@@ -46,7 +46,7 @@ object NotificationHoverUtils { ...@@ -46,7 +46,7 @@ object NotificationHoverUtils {
handler?.removeCallbacksAndMessages(null) handler?.removeCallbacksAndMessages(null)
} else { } else {
LogEx.logDebug(TAG, "handler send notification") LogEx.logDebug(TAG, "handler send notification")
NotificationUiUtil.setActionNotification(context, NotificationUiUtil.hoverActionId) NotificationUiUtil.setActionNotification(context, NotificationUiUtil.hoverActionId, where)
} }
}, time) }, time)
} }
......
...@@ -141,7 +141,7 @@ object NotificationUiUtil { ...@@ -141,7 +141,7 @@ object NotificationUiUtil {
} }
//发送通知 //发送通知
setActionNotification(context, actionId) setActionNotification(context, actionId, where)
//上报通知 //上报通知
EventUtils.event("Notification_Popup", "where=$where actionId=$actionId") EventUtils.event("Notification_Popup", "where=$where actionId=$actionId")
...@@ -156,7 +156,7 @@ object NotificationUiUtil { ...@@ -156,7 +156,7 @@ object NotificationUiUtil {
//悬停通知 //悬停通知
hoverActionId = actionId hoverActionId = actionId
NotificationHoverUtils.sendHoverNotification(context) NotificationHoverUtils.sendHoverNotification(context, where)
} }
/** /**
...@@ -185,7 +185,7 @@ object NotificationUiUtil { ...@@ -185,7 +185,7 @@ object NotificationUiUtil {
ScreenStatusReceiver.saveScreenPushedData(where, actionId) ScreenStatusReceiver.saveScreenPushedData(where, actionId)
} }
fun setActionNotification(context: Context, actionId: String) { fun setActionNotification(context: Context, actionId: String, where: String = "") {
val bigRemoteViews = RemoteViews(MyApplication.appContext.packageName, R.layout.notification_style_1) val bigRemoteViews = RemoteViews(MyApplication.appContext.packageName, R.layout.notification_style_1)
val smallRemoteViews = RemoteViews(MyApplication.appContext.packageName, R.layout.notification_style_1) val smallRemoteViews = RemoteViews(MyApplication.appContext.packageName, R.layout.notification_style_1)
...@@ -203,6 +203,8 @@ object NotificationUiUtil { ...@@ -203,6 +203,8 @@ object NotificationUiUtil {
smallRemoteViews.setTextViewText(R.id.tv_desc, desc) smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btnString) smallRemoteViews.setTextViewText(R.id.tv_btn, btnString)
testBtn(where, bigRemoteViews, smallRemoteViews)
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews)
} }
...@@ -215,6 +217,8 @@ object NotificationUiUtil { ...@@ -215,6 +217,8 @@ object NotificationUiUtil {
smallRemoteViews.setTextViewText(R.id.tv_desc, desc) smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btnString) smallRemoteViews.setTextViewText(R.id.tv_btn, btnString)
testBtn(where, bigRemoteViews, smallRemoteViews)
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews)
} }
...@@ -227,6 +231,8 @@ object NotificationUiUtil { ...@@ -227,6 +231,8 @@ object NotificationUiUtil {
smallRemoteViews.setTextViewText(R.id.tv_desc, desc) smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btnString) smallRemoteViews.setTextViewText(R.id.tv_btn, btnString)
testBtn(where, bigRemoteViews, smallRemoteViews)
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews)
} }
...@@ -239,9 +245,12 @@ object NotificationUiUtil { ...@@ -239,9 +245,12 @@ object NotificationUiUtil {
smallRemoteViews.setTextViewText(R.id.tv_desc, desc) smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btnString) smallRemoteViews.setTextViewText(R.id.tv_btn, btnString)
testBtn(where, bigRemoteViews, smallRemoteViews)
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews)
} }
ACTION_5->{
ACTION_5 -> {
val desc = "Celebrate with us! Special events and giveaways are happening now." val desc = "Celebrate with us! Special events and giveaways are happening now."
val btnString = "Join the Celebration" val btnString = "Join the Celebration"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc) bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
...@@ -250,9 +259,12 @@ object NotificationUiUtil { ...@@ -250,9 +259,12 @@ object NotificationUiUtil {
smallRemoteViews.setTextViewText(R.id.tv_desc, desc) smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btnString) smallRemoteViews.setTextViewText(R.id.tv_btn, btnString)
testBtn(where, bigRemoteViews, smallRemoteViews)
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews)
} }
ACTION_6->{
ACTION_6 -> {
val desc = "Based on your travel history, we've found new places just for you." val desc = "Based on your travel history, we've found new places just for you."
val btnString = "Discover New Places" val btnString = "Discover New Places"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc) bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
...@@ -261,9 +273,12 @@ object NotificationUiUtil { ...@@ -261,9 +273,12 @@ object NotificationUiUtil {
smallRemoteViews.setTextViewText(R.id.tv_desc, desc) smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btnString) smallRemoteViews.setTextViewText(R.id.tv_btn, btnString)
testBtn(where, bigRemoteViews, smallRemoteViews)
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews)
} }
ACTION_7->{
ACTION_7 -> {
val desc = "Ensure your travels are secure. Update your privacy settings." val desc = "Ensure your travels are secure. Update your privacy settings."
val btnString = "Secure My Trip" val btnString = "Secure My Trip"
bigRemoteViews.setTextViewText(R.id.tv_desc, desc) bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
...@@ -272,6 +287,8 @@ object NotificationUiUtil { ...@@ -272,6 +287,8 @@ object NotificationUiUtil {
smallRemoteViews.setTextViewText(R.id.tv_desc, desc) smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btnString) smallRemoteViews.setTextViewText(R.id.tv_btn, btnString)
testBtn(where, bigRemoteViews, smallRemoteViews)
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews) sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews)
} }
...@@ -282,6 +299,15 @@ object NotificationUiUtil { ...@@ -282,6 +299,15 @@ object NotificationUiUtil {
} }
} }
private fun testBtn(where: String, vararg remoteViews: RemoteViews) {
if (BuildConfig.DEBUG) {
kotlin.runCatching {
remoteViews[0].setTextViewText(R.id.tv_btn, where)
remoteViews[1].setTextViewText(R.id.tv_btn, where)
}
}
}
private fun sendCustomNotification( private fun sendCustomNotification(
context: Context, context: Context,
intent: Intent, intent: Intent,
...@@ -297,6 +323,8 @@ object NotificationUiUtil { ...@@ -297,6 +323,8 @@ object NotificationUiUtil {
CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH
) )
channel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC channel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
channel.enableVibration(false)
channel.vibrationPattern = longArrayOf(0)
notificationManager.createNotificationChannel(channel) notificationManager.createNotificationChannel(channel)
} }
......
...@@ -12,7 +12,6 @@ import com.base.locationsharewhite.helper.EventUtils ...@@ -12,7 +12,6 @@ import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.utils.AppPreferences import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.KotlinExt.currentDate import com.base.locationsharewhite.utils.KotlinExt.currentDate
import com.base.locationsharewhite.utils.LogEx import com.base.locationsharewhite.utils.LogEx
import kotlin.math.E
class PackageStatusReceiver() : BroadcastReceiver() { class PackageStatusReceiver() : BroadcastReceiver() {
...@@ -21,6 +20,7 @@ class PackageStatusReceiver() : BroadcastReceiver() { ...@@ -21,6 +20,7 @@ class PackageStatusReceiver() : BroadcastReceiver() {
private val TAG = "PackageStatusReceiver" private val TAG = "PackageStatusReceiver"
fun registerPackageStatusReceiver(context: Context) { fun registerPackageStatusReceiver(context: Context) {
LogEx.logDebug(TAG,"registerPackageStatusReceiver")
val intentFilter = IntentFilter().apply { val intentFilter = IntentFilter().apply {
addAction(Intent.ACTION_PACKAGE_ADDED) addAction(Intent.ACTION_PACKAGE_ADDED)
addAction(Intent.ACTION_PACKAGE_REMOVED) addAction(Intent.ACTION_PACKAGE_REMOVED)
...@@ -84,7 +84,7 @@ class PackageStatusReceiver() : BroadcastReceiver() { ...@@ -84,7 +84,7 @@ class PackageStatusReceiver() : BroadcastReceiver() {
"popupPackageCount=$popupPackageCount where=$POPUP_WHERE_PACKAGE" "popupPackageCount=$popupPackageCount where=$POPUP_WHERE_PACKAGE"
) )
LogEx.logDebug( LogEx.logDebug(
TAG, "Notification_Error todayPackagePush=$todayPackagePush " + "canSendNotification", "Notification_Error todayPackagePush=$todayPackagePush " +
"popupPackageCount=$popupPackageCount where=$POPUP_WHERE_PACKAGE" "popupPackageCount=$popupPackageCount where=$POPUP_WHERE_PACKAGE"
) )
} }
...@@ -106,6 +106,8 @@ class PackageStatusReceiver() : BroadcastReceiver() { ...@@ -106,6 +106,8 @@ class PackageStatusReceiver() : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) { override fun onReceive(context: Context, intent: Intent?) {
val action = intent?.action val action = intent?.action
LogEx.logDebug(TAG, "onReceive action=$action")
if (action == Intent.ACTION_PACKAGE_ADDED || action == Intent.ACTION_PACKAGE_REMOVED) { if (action == Intent.ACTION_PACKAGE_ADDED || action == Intent.ACTION_PACKAGE_REMOVED) {
NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_PACKAGE) NotificationUiUtil.sendNotificationIfCan(context, POPUP_WHERE_PACKAGE)
} }
......
...@@ -110,7 +110,7 @@ class ScreenStatusReceiver : BroadcastReceiver() { ...@@ -110,7 +110,7 @@ class ScreenStatusReceiver : BroadcastReceiver() {
"popupScreenCount=$popupScreenCount where=$POPUP_WHERE_LOCK" "popupScreenCount=$popupScreenCount where=$POPUP_WHERE_LOCK"
) )
LogEx.logDebug( LogEx.logDebug(
TAG, "canSendNotification",
"Notification_Error todayScreenPush=$todayScreenPush " + "Notification_Error todayScreenPush=$todayScreenPush " +
"popupScreenCount=$popupScreenCount where=$POPUP_WHERE_LOCK" "popupScreenCount=$popupScreenCount where=$POPUP_WHERE_LOCK"
) )
......
...@@ -13,21 +13,24 @@ import java.util.TimerTask ...@@ -13,21 +13,24 @@ import java.util.TimerTask
class TimerManager private constructor() { class TimerManager private constructor() {
private val TAG = "TimerManager"
private var taskTimer: Timer? = null private var taskTimer: Timer? = null
private var isTaskTimerActive: Boolean = false private var isTaskTimerActive: Boolean = false
fun scheduleTask(delay: Long, period: Long) { fun scheduleTask(delay: Long, period: Long) {
logDebug("TimerManager", "scheduleTask", false) logDebug(TAG, "scheduleTask")
synchronized(TimerManager::class.java) { synchronized(TimerManager::class.java) {
ensureTimerIsStopped() // 确保定时器未运行 ensureTimerIsStopped() // 确保定时器未运行
taskTimer = Timer() // 创建新的 Timer 实例 taskTimer = Timer() // 创建新的 Timer 实例
val task: TimerTask = object : TimerTask() { val task: TimerTask = object : TimerTask() {
override fun run() { override fun run() {
logDebug(TAG, "scheduleTask run")
// 确保设备处于交互状态,未锁定,且应用未暂停 // 确保设备处于交互状态,未锁定,且应用未暂停
if (ScreenStatusReceiver.isDeviceInteractive if (ScreenStatusReceiver.isDeviceInteractive
&& !ScreenStatusReceiver.isSecureLockActive && !ScreenStatusReceiver.isSecureLockActive
&& MyApplication.PAUSED_VALUE != 1 && MyApplication.PAUSED_VALUE != 1
) { ) {
logDebug(TAG, "scheduleTask send")
sendNotificationIfCan(MyApplication.appContext, PopupConstObject.POPUP_WHERE_TIMBER, null) sendNotificationIfCan(MyApplication.appContext, PopupConstObject.POPUP_WHERE_TIMBER, null)
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="80dp"
android:background="@drawable/bg_ffffff_10" android:background="@drawable/bg_ffffff_10"
android:paddingVertical="20dp"> android:paddingVertical="20dp">
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_5d7dee_18" android:background="@drawable/bg_5d7dee_18"
android:paddingHorizontal="30dp" android:paddingHorizontal="30dp"
android:paddingVertical="8dp" android:paddingVertical="8dp"
......
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