Commit 3f40efe6 authored by wanglei's avatar wanglei

...

parent a2d9f548
......@@ -6,7 +6,6 @@ import android.content.Intent;
import com.base.locationsharewhite.helper.EventUtils;
import com.base.locationsharewhite.utils.LogEx;
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject;
public class FcmReceiver extends BroadcastReceiver {
......
......@@ -6,7 +6,6 @@ import androidx.annotation.NonNull;
import com.base.locationsharewhite.helper.EventUtils;
import com.base.locationsharewhite.utils.LogEx;
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
......
package com.base.locationsharewhite.fcm
import android.content.Context
import android.os.Handler
import android.os.HandlerThread
import com.base.locationsharewhite.fcm.PopupConstObject.popup_hover_count
import com.base.locationsharewhite.fcm.PopupConstObject.popup_hover_delay
import com.base.locationsharewhite.fcm.PopupConstObject.popup_hover_status
import com.base.locationsharewhite.helper.MyApplication
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.popup_hover_count
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.popup_hover_delay
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.popup_hover_status
object NotificationHoverUtils {
......@@ -15,7 +16,6 @@ object NotificationHoverUtils {
private var handlerThread: HandlerThread? = null
private var handler: Handler? = null
/**
* 发送悬停通知
*/
......@@ -44,9 +44,7 @@ object NotificationHoverUtils {
LogEx.logDebug(TAG, "handler ${MyApplication.PAUSED_VALUE}")
if (MyApplication.PAUSED_VALUE == 1) {
handler?.removeCallbacksAndMessages(null)
return@Runnable
}
if (MyApplication.PAUSED_VALUE != 1) {
} else {
LogEx.logDebug(TAG, "handler send notification")
NotificationUiUtil.setActionNotification(context, NotificationUiUtil.hoverActionId)
}
......
......@@ -42,9 +42,9 @@ import kotlin.random.Random
object NotificationUiUtil {
private val TAG = "NotificationUiUtil"
const val CHANNEL_ID = "browser_notification_id" // 通知渠道ID
const val CHANNEL_NAME = "browser_fcm_channel" // 通知渠道名称
var NOTIFICATION_ID = 8999
private val CHANNEL_ID = "location_notification_id" // 通知渠道ID
private val CHANNEL_NAME = "location_fcm_channel" // 通知渠道名称
private var NOTIFICATION_ID = 8999
private fun currentDate(): String {
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
......@@ -155,85 +155,85 @@ object NotificationUiUtil {
//
when (actionId) {
else -> {
EventUtils.event("Notification_Error", "unKnow actionId actionId=$actionId")
else -> {
EventUtils.event("Notification_Error", "unKnow actionId actionId=$actionId")
}
}
}
}
private fun sendCustomNotification(
context: Context,
intent: Intent,
bigRemoteViews: RemoteViews,
smallRemoteViews: RemoteViews,
) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//创建channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH
)
channel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
notificationManager.createNotificationChannel(channel)
}
private fun sendCustomNotification(
context: Context,
intent: Intent,
bigRemoteViews: RemoteViews,
smallRemoteViews: RemoteViews,
) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//创建channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH
)
channel.lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
notificationManager.createNotificationChannel(channel)
}
// Create the notification
val builder: NotificationCompat.Builder = NotificationCompat.Builder(context, CHANNEL_ID)
// Create the notification
val builder: NotificationCompat.Builder = NotificationCompat.Builder(context, CHANNEL_ID)
//设置状态栏内的小图标
val smallIcon = IconCompat.createFromIcon(
context, Icon.createWithResource(
context, R.mipmap.logo
//设置状态栏内的小图标
val smallIcon = IconCompat.createFromIcon(
context, Icon.createWithResource(
context, R.mipmap.logo
)
)
)
smallIcon?.let {
builder.setSmallIcon(smallIcon)
}
builder.setContentTitle(context.resources.getString(R.string.app_name))
.setContentText("notification")
val requestCode = Random.nextInt(1000)
val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE)
builder.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setAutoCancel(true)
var small: RemoteViews? = bigRemoteViews
//Android 12以下需要适配小RemoteViews
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
small = smallRemoteViews
}
// 设置小视图
builder.setCustomContentView(smallRemoteViews)
smallIcon?.let {
builder.setSmallIcon(smallIcon)
}
builder.setContentTitle(context.resources.getString(R.string.app_name))
.setContentText("notification")
val requestCode = Random.nextInt(1000)
val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE)
builder.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setAutoCancel(true)
var small: RemoteViews? = bigRemoteViews
//Android 12以下需要适配小RemoteViews
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
small = smallRemoteViews
}
// 设置小视图
builder.setCustomContentView(smallRemoteViews)
// 设置悬浮通知视图(Android 12 及以上)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setCustomHeadsUpContentView(bigRemoteViews)
}
// 设置悬浮通知视图(Android 12 及以上)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setCustomHeadsUpContentView(bigRemoteViews)
}
// 设置大视图
builder.setCustomBigContentView(bigRemoteViews)
// 设置大视图
builder.setCustomBigContentView(bigRemoteViews)
notificationManager.notify(NOTIFICATION_ID, builder.build())
}
notificationManager.notify(NOTIFICATION_ID, builder.build())
}
val looper_actionId = listOf(
ACTION_APP_PROCESS,
)
val looper_actionId = listOf(
ACTION_APP_PROCESS,
)
var actionIdList = arrayListOf<String>()
fun getNextActionId(): String {
if (actionIdList.isEmpty()) {
actionIdList.addAll(looper_actionId)
}
val next = actionIdList[0]
actionIdList.removeAt(0)
if (BuildConfig.DEBUG) {
var actionIdList = arrayListOf<String>()
fun getNextActionId(): String {
if (actionIdList.isEmpty()) {
actionIdList.addAll(looper_actionId)
}
val next = actionIdList[0]
actionIdList.removeAt(0)
if (BuildConfig.DEBUG) {
// return NOTIFICATION_ACTION_WEATHER
}
return next
}
return next
}
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ object PopupConstObject {
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"//悬停调用
//推送总开关 0 关 1开
......@@ -44,4 +43,13 @@ object PopupConstObject {
AppPreferences.getInstance().put("topic_number", value, true)
}
const val ACTION_STAY_HOME = "action_stay_home"
const val ACTION_STAY_MY_CODE = "action_stay_my_code"
const val ACTION_STAY_SHARE = "action_stay_share"
const val ACTION_STAY_SETTING = "action_stay_setting"
const val ACTION_SHARE_LOCATION = "action_share_location"
const val ACTION_ENABLE_LOCATION = "action_enable_location"
const val ACTION_COPY_CODE="action_copy_code"
}
\ No newline at end of file
......@@ -4,12 +4,12 @@ import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.locationsharewhite.fcm.PopupConstObject
import com.base.pdfreaderallpdfreader.BuildConfig
import com.base.pdfreaderallpdfreader.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.pdfreaderallpdfreader.helper.EventUtils
import com.base.pdfreaderallpdfreader.utils.AppPreferences
import com.base.pdfreaderallpdfreader.utils.LogEx
import com.base.locationsharewhite.helper.EventUtils
import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx
class AlarmJobReceiver : BroadcastReceiver() {
......
package com.base.pdfreaderallpdfreader.fcm.alarm
package com.base.locationsharewhite.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.pdfreaderallpdfreader.BuildConfig
import com.base.pdfreaderallpdfreader.fcm.work.RepeatingWorker.Companion.schedulePeriodicWork
import com.base.pdfreaderallpdfreader.service.StayJobService.Companion.startJob
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.work.RepeatingWorker.Companion.schedulePeriodicWork
import com.base.locationsharewhite.service.StayJobService.Companion.startJob
import com.base.pdfreaderallpdfreader.fcm.alarm.AlarmJobReceiver
import java.util.Calendar
object AlarmUtils {
......
......@@ -27,5 +27,4 @@ object ConstConfig {
const val openAdmobId = "/6499/example/app-open"
const val bannerAdmobId = "ca-app-pub-3940256099942544/9214581111"
const val ACTION_APP_PROCESS = ""
}
\ No newline at end of file
package com.base.locationsharewhite.service
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.job.JobInfo
import android.app.job.JobParameters
import android.app.job.JobScheduler
import android.app.job.JobService
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.graphics.BitmapFactory
import android.graphics.drawable.Icon
import android.os.Build
import android.os.CountDownTimer
import android.provider.MediaStore
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.IconCompat
import androidx.work.Configuration
import com.base.locationsharewhite.R
import com.base.locationsharewhite.service.StayNotification.createPermanentNotification
import com.base.locationsharewhite.utils.LogEx
import kotlin.random.Random
/**
* 常驻通知栏
*/
class StayJobService : JobService() {
init {
val builder = Configuration.Builder()
builder.setJobSchedulerJobIdRange(0, 1000)
}
private val TAG = "StayJobService"
companion object {
private val NOTIFICATION_PERMANENT_ID = 186
var isRunning = false
private const val JOB_INFO_ID: Int = 101
private const val JOB_PERIODIC: Long = 5 * 1000L
fun Context.startJob() {
if (isRunning) return
val jobScheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler
val componentName = ComponentName(this, StayJobService::class.java)
val jobInfo = JobInfo.Builder(JOB_INFO_ID, componentName)
.setMinimumLatency(30000)
.build()
jobScheduler.schedule(jobInfo)
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return super.onStartCommand(intent, flags, startId)
}
private fun startForeground() {
val notification = createPermanentNotification(applicationContext)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
NOTIFICATION_PERMANENT_ID,
notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
} else {
startForeground(NOTIFICATION_PERMANENT_ID, notification)
}
isRunning = true
}
private fun notifyForeground() {
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(
NOTIFICATION_PERMANENT_ID,
createPermanentNotification(applicationContext)
)
}
override fun onDestroy() {
isRunning = false
super.onDestroy()
}
override fun onCreate() {
LogEx.logDebug(TAG, "onCreate isRunning=$isRunning")
if (!isRunning) {
isRunning = true
startForeground()
Timer().start()
}
super.onCreate()
}
override fun onStartJob(params: JobParameters?): Boolean {
return true
}
override fun onStopJob(params: JobParameters?): Boolean {
return false
}
private inner class Timer() : CountDownTimer(30000, 1000) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
notifyForeground()
Timer().start()
}
}
}
package com.base.locationsharewhite.service
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.drawable.Icon
import android.os.Build
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.IconCompat
import com.base.locationsharewhite.R
import com.base.locationsharewhite.ui.main.MainActivity
object StayNotification {
private fun customRemoteViews(contentView: RemoteViews, expendView: RemoteViews) {
// val requestCode1 = Random.nextInt(1800)
// val intent1 = Intent(context, MyStartActivity::class.java).apply {
// putExtra("actionId", ConstObject.NOTIFICATION_ACTION_LOG)
// }
// val pendingIntent1 =
// PendingIntent.getActivity(
// context,
// requestCode1,
// intent1,
// PendingIntent.FLAG_IMMUTABLE
// )
// contentView.setOnClickPendingIntent(R.id.fl_1, pendingIntent1)
// expendView.setOnClickPendingIntent(R.id.fl_1, pendingIntent1)
//
// val requestCode2 = Random.nextInt(1800)
// val intent2 = Intent(context, MyStartActivity::class.java).apply {
// putExtra("actionId", ConstObject.NOTIFICATION_ACTION_DOCUMENT)
// }
// val pendingIntent2 =
// PendingIntent.getActivity(
// context,
// requestCode2,
// intent2,
// PendingIntent.FLAG_IMMUTABLE
// )
// contentView.setOnClickPendingIntent(R.id.ll_2, pendingIntent2)
// expendView.setOnClickPendingIntent(R.id.ll_2, pendingIntent2)
//
// val requestCode3 = Random.nextInt(1800)
// val intent3 = Intent(context, MyStartActivity::class.java).apply {
// putExtra("actionId", ConstObject.NOTIFICATION_ACTION_BOOKMARK)
// }
// val pendingIntent3 =
// PendingIntent.getActivity(
// context,
// requestCode3,
// intent3,
// PendingIntent.FLAG_IMMUTABLE
// )
// contentView.setOnClickPendingIntent(R.id.ll_3, pendingIntent3)
// expendView.setOnClickPendingIntent(R.id.ll_3, pendingIntent3)
//
//
// val requestCode4 = Random.nextInt(1800)
// val intent4 = Intent(context, MyStartActivity::class.java).apply {
// putExtra("actionId", ConstObject.NOTIFICATION_ACTION_NEW_IMAGE_PDF)
// }
// val pendingIntent4 =
// PendingIntent.getActivity(
// context,
// requestCode4,
// intent4,
// PendingIntent.FLAG_IMMUTABLE
// )
// contentView.setOnClickPendingIntent(R.id.ll_4, pendingIntent4)
// expendView.setOnClickPendingIntent(R.id.ll_4, pendingIntent4)
}
fun createPermanentNotification(context: Context): Notification {
val channelName = "Permanent Foreground Service Channel"
val channelId = "permanent_channel"
val contentView = RemoteViews(context.packageName, R.layout.stay_notification_big)
val expendView = RemoteViews(context.packageName, R.layout.stay_notification_big)
customRemoteViews(contentView, expendView)
val builder = NotificationCompat.Builder(context, channelId)
val smallIcon = IconCompat.createFromIcon(
context, Icon.createWithResource(
context, R.mipmap.logo
)
)
smallIcon?.let {
builder.setSmallIcon(smallIcon) //设置状态栏内的小图标
}
val nfIntent = Intent(context, MainActivity::class.java)
val pendingIntent =
PendingIntent.getActivity(context, 0, nfIntent, PendingIntent.FLAG_IMMUTABLE)
builder.setLargeIcon(
BitmapFactory.decodeResource(
context.resources,
R.mipmap.logo
)
)
builder.setContentTitle(context.resources.getString(R.string.app_name))
builder.setContentIntent(pendingIntent) //设置PendingIntent
builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) //设置通知公开可见
builder.setAutoCancel(false)
builder.setOngoing(true)
builder.setPriority(NotificationCompat.PRIORITY_MAX) //优先级为:重要通知
builder.setWhen(System.currentTimeMillis())
builder.setCustomContentView(contentView)
builder.setCustomBigContentView(expendView)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel =
NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_LOW)
channel.lockscreenVisibility = 1
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
builder.setChannelId(channelId)
}
return builder.build()
}
}
\ No newline at end of file
......@@ -11,9 +11,8 @@ import com.base.locationsharewhite.bean.ConstObject.ifAgreePrivacy
import com.base.locationsharewhite.bean.ConstObject.isFirstLauncher
import com.base.locationsharewhite.databinding.ActivitySplashBinding
import com.base.locationsharewhite.fcm.NotificationHoverUtils
import com.base.locationsharewhite.fcm.PopupConstObject
import com.base.locationsharewhite.helper.BaseActivity
import com.base.locationsharewhite.helper.config.ConstConfig
import com.base.locationsharewhite.service.StayNotificationService.Companion.startStayNotification
import com.base.locationsharewhite.ui.howuse.HowUseActivity
import com.base.locationsharewhite.ui.main.LocationCodeActivity
import com.base.locationsharewhite.ui.main.LocationShareActivity
......@@ -40,16 +39,15 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
override val binding: ActivitySplashBinding by lazy {
ActivitySplashBinding.inflate(layoutInflater)
}
private var actionId: Int? = null
private var actionId: String? = null
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
// binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
splashPresenter = SplashPresenter(this)
startStayNotification()
actionId = intent.extras?.getInt("actionId")
actionId = intent.extras?.getString("actionId")
LogEx.logDebug(TAG, "actionId=$actionId")
if (actionId != null) {
NotificationHoverUtils.stopNotificationHandler()
......@@ -122,45 +120,45 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(), SplashView {
}
private fun handleActionIdJump() {
actionId = intent.extras?.getInt("actionId")
actionId = intent.extras?.getString("actionId")
LogEx.logDebug(TAG, "handleActionIdJump actionId=$actionId")
when (actionId) {
ConstConfig.ACTION_STAY_HOME -> {
PopupConstObject.ACTION_STAY_HOME -> {
startActivity(Intent(this, MainActivity::class.java).apply {
putExtra("actionId", actionId)
})
}
ConstConfig.ACTION_STAY_MY_CODE -> {
PopupConstObject.ACTION_STAY_MY_CODE -> {
startActivity(Intent(this, LocationCodeActivity::class.java).apply {
// putExtra("actionId", actionId)
})
}
ConstConfig.ACTION_STAY_SHARE -> {
PopupConstObject.ACTION_STAY_SHARE -> {
startActivity(Intent(this, LocationShareActivity::class.java).apply {
// putExtra("actionId", actionId)
})
}
ConstConfig.ACTION_STAY_SETTING -> {
PopupConstObject.ACTION_STAY_SETTING -> {
startActivity(Intent(this, SettingActivity::class.java).apply {
// putExtra("actionId", actionId)
})
}
ConstConfig.ACTION_SHARE_LOCATION -> {
PopupConstObject.ACTION_SHARE_LOCATION -> {
startActivity(Intent(this, LocationShareActivity::class.java).apply {})
}
ConstConfig.ACTION_ENABLE_LOCATION -> {
PopupConstObject.ACTION_ENABLE_LOCATION -> {
startActivity(Intent(this, MainActivity::class.java).apply {
putExtra("actionId", actionId)
})
}
ConstConfig.ACTION_COPY_CODE -> {
PopupConstObject.ACTION_COPY_CODE -> {
startActivity(Intent(this, LocationCodeActivity::class.java).apply {
putExtra("actionId", actionId)
})
......
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