Commit 4de9a733 authored by wanglei's avatar wanglei

========需要同步代码========处理通知进入页面通知不消失

parent 833ea4c4
......@@ -14,9 +14,13 @@ import androidx.core.view.isVisible
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.BarUtils
import com.test.basd.onecleanmaster.databinding.ActivityLayoutSplashBinding
import com.test.basd.onecleanmaster.display.CloseNotificationReceiver
import com.test.basd.onecleanmaster.display.NotificationHelper
import com.test.basd.onecleanmaster.display.NotificationUtils
import com.test.basd.onecleanmaster.helps.BaseActivity
import com.test.basd.onecleanmaster.helps.BaseApplication.Companion.context
import com.test.basd.onecleanmaster.helps.ConfigHelper
import com.test.basd.onecleanmaster.helps.LogEx
import com.test.basd.onecleanmaster.helps.ads.AdmobUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
......@@ -25,7 +29,7 @@ import kotlinx.coroutines.launch
@SuppressLint("CustomSplashScreen")
class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
PrivacyAgreementManager.onUserPrivacyAggreementListener, ProgressManager.ProgressListener {
private val TAG = "NewSplashActivity"
private fun initStatusBar() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
......@@ -43,11 +47,11 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
private var mProgressManager: ProgressManager? = null
override fun initView() {
cancelNotification()
initStatusBar()
if (isDestroyed) {
return
}
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
notificationManager?.cancel(NotificationUtils.NOTIFICATION_TAG, 10086)
mProgressManager = ProgressManager(binding, this)
......@@ -62,6 +66,22 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
}
private fun cancelNotification() {
var jumpType = intent.getIntExtra("type", 0)
if (jumpType == 0) {
val uri = intent.data
val str = (uri?.getQueryParameter("type") ?: "0")
jumpType = str.toIntOrNull() ?: 0
}
LogEx.logDebug(TAG, "jumpType=$jumpType")
if (jumpType != 0) {
val cancelIntent = Intent(context, CloseNotificationReceiver::class.java)
cancelIntent.action = CloseNotificationReceiver.action
cancelIntent.putExtra("notificationId", NotificationHelper.notificationId)
context.sendBroadcast(cancelIntent)
}
}
override fun onAgreePrivacy() {
MainScope().launch(Dispatchers.IO) {
ConfigHelper.appList = AppUtils.getAppsInfo().shuffled()
......
......@@ -30,12 +30,15 @@ import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_RECENT_USE_APP
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_SIMILAR_IMAGE
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_UNINSTALL_PACKAGE_PUSH
import com.test.basd.onecleanmaster.bean.ConfigBean.Companion.ID_VIRUS_PUSH
import com.test.basd.onecleanmaster.display.CloseNotificationReceiver
import com.test.basd.onecleanmaster.helps.ConfigHelper
import com.test.basd.onecleanmaster.helps.LogEx
import com.test.basd.onecleanmaster.notificationclean.NotificationCleanActivity
import com.test.basd.onecleanmaster.notificationclean.NotificationGuestActivity
object SplashJumpUtils {
private val TAG = "SplashJumpUtils"
fun jumpNextPage(context: Activity) {
var jumpType = context.intent.getIntExtra("type", 0)
......@@ -45,6 +48,7 @@ object SplashJumpUtils {
val str = (uri?.getQueryParameter("type") ?: "0")
jumpType = str.toIntOrNull() ?: 0
}
LogEx.logDebug(TAG, "jumpType=$jumpType")
when (jumpType) {
//=================================主动广播=======================================
ID_JUNK_CLEAN_PUSH -> {
......
......@@ -4,9 +4,13 @@ import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.test.basd.onecleanmaster.helps.LogEx
class CloseNotificationReceiver : BroadcastReceiver() {
private val TAG = "CloseNotificationReceiver"
override fun onReceive(context: Context?, intent: Intent?) {
LogEx.logDebug(TAG, "onReceive")
intent?.let {
val notificationId = it.getIntExtra("notificationId", -1)
if (notificationId != -1 && it.action != "DELETE_NOTIFICATION") {
......
......@@ -291,67 +291,4 @@ object NotificationHelper {
)
}
//创建通知通道
private fun createNotificationChannel(
context: Context,
channelId: String = CHANNEL_ID,
channelName: String = CHANNEL_NAME,
) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val importance = NotificationManager.IMPORTANCE_HIGH
val channel = NotificationChannel(channelId, channelName, importance).apply {
enableLights(true)
enableVibration(false)
vibrationPattern = longArrayOf(0)
lightColor = Color.RED
}
// Register the channel with the system
val notificationManager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
@SuppressLint("MissingPermission")
//Manifest.permission.POST_NOTIFICATIONS
fun showNotification(context: Context, intent: Intent, remoteViews: RemoteViews) {
createNotificationChannel(context)
val flag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE
} else {
FLAG_UPDATE_CURRENT
}
//requestCode每次需要改变
val requestCode = Random.nextInt(0, 1000)
val pendingIntent = PendingIntent.getActivity(
context, requestCode, intent, flag
)
val title = intent.getStringExtra("title")
val desc = intent.getStringExtra("desc")
val builder = NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.mipmap.logo_small)
.setCustomContentView(remoteViews)
.setCustomBigContentView(remoteViews)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setColor(Color.TRANSPARENT)
.setContentTitle(title)
.setContentText(desc)
.setAutoCancel(true)
.setOngoing(true)
.setDefaults(NotificationCompat.FLAG_ONLY_ALERT_ONCE)
.setVibrate(longArrayOf(0))
.setContentIntent(pendingIntent)
val notification: Notification = builder.build()
val notificationManager = context.getSystemService(Service.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(notificationId, notification)
}
}
app/src/main/res/drawable-xxhdpi/l_lower.png

518 Bytes | W: | H:

app/src/main/res/drawable-xxhdpi/l_lower.png

453 Bytes | W: | H:

app/src/main/res/drawable-xxhdpi/l_lower.png
app/src/main/res/drawable-xxhdpi/l_lower.png
app/src/main/res/drawable-xxhdpi/l_lower.png
app/src/main/res/drawable-xxhdpi/l_lower.png
  • 2-up
  • Swipe
  • Onion skin
app/src/main/res/drawable-xxhdpi/l_upper.png

487 Bytes | W: | H:

app/src/main/res/drawable-xxhdpi/l_upper.png

460 Bytes | W: | H:

app/src/main/res/drawable-xxhdpi/l_upper.png
app/src/main/res/drawable-xxhdpi/l_upper.png
app/src/main/res/drawable-xxhdpi/l_upper.png
app/src/main/res/drawable-xxhdpi/l_upper.png
  • 2-up
  • Swipe
  • Onion skin
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