Commit 57a3ca66 authored by wanglei's avatar wanglei

...通知功能

parent ed0a344d
...@@ -29,8 +29,6 @@ class ScanJunkActivity : BaseActivity<ActivityLayoutScanJunkBinding>() { ...@@ -29,8 +29,6 @@ class ScanJunkActivity : BaseActivity<ActivityLayoutScanJunkBinding>() {
BarUtils.setStatusBarColor(this, Color.TRANSPARENT) BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
binding.root.updatePadding(top = BarUtils.getStatusBarHeight()) binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
AdmobNativeUtils.showNativeAd(this, binding.flAd)
if (checkStorePermission()) { if (checkStorePermission()) {
playLottie() playLottie()
} else { } else {
......
...@@ -69,7 +69,6 @@ class FileScanActivity : BaseActivity<ActivityFileScanBinding>() { ...@@ -69,7 +69,6 @@ class FileScanActivity : BaseActivity<ActivityFileScanBinding>() {
binding.ivIcon.setImageResource(R.mipmap.tu_videos_scan) binding.ivIcon.setImageResource(R.mipmap.tu_videos_scan)
} }
} }
AdmobNativeUtils.showNativeAd(this, binding.flAd)
} }
override fun initListener() { override fun initListener() {
...@@ -105,9 +104,9 @@ class FileScanActivity : BaseActivity<ActivityFileScanBinding>() { ...@@ -105,9 +104,9 @@ class FileScanActivity : BaseActivity<ActivityFileScanBinding>() {
val sharedFlow: SharedFlow<String> = mutableSharedFlow val sharedFlow: SharedFlow<String> = mutableSharedFlow
val filter = when (scanType) { val filter = when (scanType) {
ConstObject.SCAN_PHOTOS -> ::isImage SCAN_PHOTOS -> ::isImage
ConstObject.SCAN_DOCUMENTS -> ::isDocument SCAN_DOCUMENTS -> ::isDocument
ConstObject.SCAN_VIDEOS -> ::isVideo SCAN_VIDEOS -> ::isVideo
else -> ::isImage else -> ::isImage
} }
val root = Environment.getExternalStorageDirectory() val root = Environment.getExternalStorageDirectory()
......
...@@ -4,6 +4,14 @@ import com.base.datarecovery.utils.SPUtils ...@@ -4,6 +4,14 @@ import com.base.datarecovery.utils.SPUtils
object ConstObject { object ConstObject {
const val ID_JUNK_CLEAN_PUSH = 11001 //清理垃圾
const val ID_SIMILAR_IMAGE = 11015//清理相似图片
const val ID_SCREENSHOT_CLEAN = 12000//截图清理
const val ID_RECOVERY_PHOTOS = 0
const val ID_RECOVERY_VIDEOS = 0
const val ID_RECOVERY_DOCUMENTS = 0
const val ID_PRIVACY_SPACE = 0
const val JUNK_CLEANER = "Junk Cleaner" const val JUNK_CLEANER = "Junk Cleaner"
const val REPEAT_PHOTOS = "Repeat Photos" const val REPEAT_PHOTOS = "Repeat Photos"
const val PHOTO_COMPRESS = "Photo Compress" const val PHOTO_COMPRESS = "Photo Compress"
......
package com.base.datarecovery.fcm
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.base.datarecovery.utils.SPUtils
class CloseNotificationReceiver : BroadcastReceiver() {
companion object {
var Action = "CANCEL_NOTIFICATION"
var NotificationId = "NOTIFICATION_ID"
}
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent?.action
if (action != null && action == "CANCEL_NOTIFICATION") {
var notificationId = intent.getIntExtra(NotificationId, 0)
val notificationManager = context!!.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val actionS: Int = SPUtils.getInstance().getInt("actionS", 0)
if (actionS == 0) {
notificationId = 0
}
notificationManager.cancel(notificationId)
}
}
}
\ No newline at end of file
package com.base.datarecovery.fcm
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
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.datarecovery.R
import com.base.datarecovery.activity.SplashActivity
import com.base.datarecovery.bean.ConstObject.ID_JUNK_CLEAN_PUSH
import com.base.datarecovery.bean.ConstObject.ID_PRIVACY_SPACE
import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_DOCUMENTS
import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_PHOTOS
import com.base.datarecovery.bean.ConstObject.ID_RECOVERY_VIDEOS
import com.base.datarecovery.bean.ConstObject.ID_SCREENSHOT_CLEAN
import com.base.datarecovery.bean.ConstObject.ID_SIMILAR_IMAGE
import com.base.datarecovery.utils.SPUtils
import java.util.Random
/**
* 构建发送通知
*/
object NotificationUtil {
private const val CHANNEL_ID = "recovery_notification_id" // 通知渠道ID
private const val CHANNEL_NAME = "recovery_fcm_channel" // 通知渠道名称
fun sendNotification(context: Context, actionId: Int) {
val bigRemoteViews = RemoteViews(context.packageName, R.layout.notification_common)
val smallRemoteViews = RemoteViews(context.packageName, R.layout.notification_common_small)
var icon = 0
var desc = ""
var btn = ""
when (actionId) {
ID_JUNK_CLEAN_PUSH -> {
icon = R.mipmap.cleanjunk_ss
desc = "Free up space on your phone! Clean unwanted junk files now."
btn = "Clean Up Space"
}
ID_SIMILAR_IMAGE -> {
icon = R.mipmap.h_similar
desc = "Check similar photos to release more space"
btn = "Clean up"
}
ID_SCREENSHOT_CLEAN -> {
// icon = R.mipmap.similar
desc = "Streamline your photo album! Remove old and unnecessary screenshots."
btn = "Remove Screenshots"
}
ID_RECOVERY_PHOTOS -> {
// icon = R.mipmap.h_similar
desc = "Has a photo gone missing? Try our recovery tool to get it back."
btn = "Retrieve Photo"
}
ID_RECOVERY_VIDEOS -> {
// icon = R.mipmap.h_similar
desc = "Regain lost video moments. Start your video recovery now!"
btn = "Recover Video"
}
ID_RECOVERY_DOCUMENTS -> {
// icon = R.mipmap.h_similar
desc = "Lost a vital document? Our recovery service might be able to help."
btn = "Restore Document"
}
ID_PRIVACY_SPACE -> {
// icon = R.mipmap.h_similar
desc = "Secure your private content. Tuck away photos and videos in your hidden space."
btn = "Hide Content"
}
}
bigRemoteViews.setImageViewResource(R.id.iv_icon, icon)
bigRemoteViews.setTextViewText(R.id.tv_desc, desc)
bigRemoteViews.setTextViewText(R.id.tv_btn, btn)
smallRemoteViews.setImageViewResource(R.id.iv_icon, icon)
smallRemoteViews.setTextViewText(R.id.tv_desc, desc)
smallRemoteViews.setTextViewText(R.id.tv_btn, btn)
//取消按钮
bigRemoteViews.setOnClickPendingIntent(R.id.fl_cancel, cancelNotificationPendingIntent(context, actionId))
//跳转
val intent = Intent(context, SplashActivity::class.java)
intent.putExtra("actionId", actionId)
val btnRequestCode = Random().nextInt(1000)
val btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, PendingIntent.FLAG_IMMUTABLE)
bigRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent)
smallRemoteViews.setOnClickPendingIntent(R.id.tv_btn, btnPendingIntent)
//构建发送通知
sendCustomNotification(context, actionId, intent, bigRemoteViews, smallRemoteViews)
}
private fun cancelNotificationPendingIntent(context: Context, actionId: Int): PendingIntent {
val cancelIntent = Intent(context, CloseNotificationReceiver::class.java)
cancelIntent.setAction(CloseNotificationReceiver.Action)
cancelIntent.putExtra(CloseNotificationReceiver.NotificationId, actionId)
val broadcastRequestCode = Random().nextInt(1000)
return PendingIntent.getBroadcast(context, broadcastRequestCode, cancelIntent, PendingIntent.FLAG_IMMUTABLE)
}
private fun sendCustomNotification(
context: Context,
actionId: Int,
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)
//设置状态栏内的小图标
val smallIcon = IconCompat.createFromIcon(
context, Icon.createWithResource(
context, R.drawable.icon_100
)
)
smallIcon?.let {
builder.setSmallIcon(smallIcon)
}
builder.setContentTitle(context.resources.getString(R.string.app_name))
.setContentText("notification")
val requestCode = kotlin.random.Random.nextInt(1000)
val pendingIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_IMMUTABLE)
builder.setContentIntent(pendingIntent)
.setDeleteIntent(cancelNotificationPendingIntent(context, actionId))
.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.setContent(small)
builder.setCustomHeadsUpContentView(small)
builder.setCustomContentView(small)
builder.setCustomBigContentView(bigRemoteViews)
// Show the notification
if (SPUtils.getInstance().getInt("actionS", 1) == 1) {
notificationManager.notify(intent.getIntExtra("actionId", actionId), builder.build())
} else {
notificationManager.notify(actionId, builder.build())
}
SPUtils.getInstance().put("last_notification_time", System.currentTimeMillis())
}
}
\ No newline at end of file
...@@ -132,10 +132,5 @@ ...@@ -132,10 +132,5 @@
</LinearLayout> </LinearLayout>
<FrameLayout
android:id="@+id/fl_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -54,12 +54,6 @@ ...@@ -54,12 +54,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
<FrameLayout
android:id="@+id/fl_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="208dp"
android:layout_marginHorizontal="10dp"
android:background="@drawable/bg_ffffff_10"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="11dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_icon_small"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center_vertical"
android:src="@mipmap/logo"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="5dp"
android:layout_weight="1"
android:text="@string/app_name"
android:textColor="#4F565E" />
<FrameLayout
android:id="@+id/fl_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:padding="5dp">
<!-- 适应混淆规则这个xml中不引用@string-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="cancel"
android:textColor="#999999"
android:textStyle="bold"
tools:ignore="HardcodedText" />
</FrameLayout>
</LinearLayout>
<ImageView
android:id="@+id/iv_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<FrameLayout
android:id="@+id/fl_btn"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginHorizontal="30dp"
android:layout_marginVertical="8dp"
android:clickable="true"
android:focusable="true">
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoStart="true"
android:flipInterval="100">
<ImageView
android:id="@+id/iv_btn_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_1"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_2"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_3"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_4"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_5"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_6"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_7"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_8"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_9"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_10"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_11"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_12"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_13"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_13"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_btn_14"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/btn_14"
tools:ignore="ContentDescription" />
</ViewFlipper>
<TextView
android:id="@+id/tv_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:gravity="center"
android:textColor="#ffffffff"
android:textSize="17sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
</FrameLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/bg_ffffff_10"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:ignore="UselessParent">
<ImageView
android:id="@+id/iv_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:gravity="center"
android:textColor="#000000"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="12dp"
android:background="@drawable/bg_567dfd_15"
android:paddingHorizontal="25dp"
android:paddingVertical="8dp"
android:text="View"
android:textColor="@color/white"
android:textSize="15sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</FrameLayout>
\ No newline at end of file
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