Commit d91e3fae authored by maxiaoliang's avatar maxiaoliang

删除通知相关的所有代码,移除fieebase崩溃分析,fcm依赖

parent ca2ea7b1
...@@ -91,7 +91,7 @@ dependencies { ...@@ -91,7 +91,7 @@ dependencies {
implementation 'com.airbnb.android:lottie:6.4.0' implementation 'com.airbnb.android:lottie:6.4.0'
implementation platform('com.google.firebase:firebase-bom:32.3.1') implementation platform('com.google.firebase:firebase-bom:32.3.1')
implementation 'com.google.firebase:firebase-analytics:21.6.2' implementation 'com.google.firebase:firebase-analytics:21.6.2'
implementation 'com.google.firebase:firebase-crashlytics' // implementation 'com.google.firebase:firebase-crashlytics'
// implementation("com.squareup.okhttp3:okhttp:4.9.0") // implementation("com.squareup.okhttp3:okhttp:4.9.0")
// implementation("com.squareup.okhttp3:logging-interceptor:4.9.0") // implementation("com.squareup.okhttp3:logging-interceptor:4.9.0")
implementation("com.github.JavaNoober.BackgroundLibrary:libraryx:1.7.6") implementation("com.github.JavaNoober.BackgroundLibrary:libraryx:1.7.6")
...@@ -102,10 +102,10 @@ dependencies { ...@@ -102,10 +102,10 @@ dependencies {
// kapt("androidx.room:room-compiler:$roomVersion") // kapt("androidx.room:room-compiler:$roomVersion")
// implementation("androidx.room:room-ktx:$roomVersion") // implementation("androidx.room:room-ktx:$roomVersion")
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
implementation 'com.belerweb:pinyin4j:2.5.1' // implementation 'com.belerweb:pinyin4j:2.5.1'
implementation("com.google.firebase:firebase-messaging") //implementation("com.google.firebase:firebase-messaging")
// implementation("com.facebook.android:facebook-android-sdk:[8,9)") // implementation("com.facebook.android:facebook-android-sdk:[8,9)")
implementation 'com.makeramen:roundedimageview:2.3.0' implementation 'com.makeramen:roundedimageview:2.3.0'
......
...@@ -117,13 +117,8 @@ ...@@ -117,13 +117,8 @@
<meta-data <meta-data
android:name="com.google.android.gms.ads.flag.NATIVE_AD_DEBUGGER_ENABLED" android:name="com.google.android.gms.ads.flag.NATIVE_AD_DEBUGGER_ENABLED"
android:value="false" /> android:value="false" />
<service
android:name=".display.NotificationService"
android:permission="android.permission.FOREGROUND_SERVICE" />
<service
android:name=".service.FlashlightService"
android:exported="true"
tools:ignore="ExportedService" />
<activity <activity
android:name=".activity.photocompress.photo.StartCompressionPhotoActivity" android:name=".activity.photocompress.photo.StartCompressionPhotoActivity"
...@@ -146,14 +141,7 @@ ...@@ -146,14 +141,7 @@
android:screenOrientation="portrait" android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" /> tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<receiver
android:name=".display.CloseNotificationReceiver"
android:exported="true"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="com.file.notification.CloseNotificationReceiver" />
</intent-filter>
</receiver>
<meta-data <meta-data
android:name="com.facebook.sdk.ApplicationId" android:name="com.facebook.sdk.ApplicationId"
......
...@@ -4,7 +4,6 @@ import android.content.Intent ...@@ -4,7 +4,6 @@ import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import com.test.easy.easycleanerjunk.databinding.ActivitySettingBinding import com.test.easy.easycleanerjunk.databinding.ActivitySettingBinding
import com.test.easy.easycleanerjunk.display.NotificationService
import com.test.easy.easycleanerjunk.helps.BaseActivity import com.test.easy.easycleanerjunk.helps.BaseActivity
import com.test.easy.easycleanerjunk.helps.ConfigHelper import com.test.easy.easycleanerjunk.helps.ConfigHelper
import com.test.easy.easycleanerjunk.helps.ConfigHelper.allNotification import com.test.easy.easycleanerjunk.helps.ConfigHelper.allNotification
...@@ -27,15 +26,15 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() { ...@@ -27,15 +26,15 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() {
finishToMain() finishToMain()
// } // }
} }
binding.switchRemainNotification.setOnCheckedChangeListener { buttonView, isChecked -> // binding.switchRemainNotification.setOnCheckedChangeListener { buttonView, isChecked ->
remainNotification = isChecked // remainNotification = isChecked
if (isChecked) { // if (isChecked) {
startNotification() // startNotification()
} else { // } else {
val serviceIntent = Intent(this, NotificationService::class.java) // val serviceIntent = Intent(this, NotificationService::class.java)
stopService(serviceIntent) // stopService(serviceIntent)
} // }
} // }
binding.cardPrivacy.setOnClickListener { binding.cardPrivacy.setOnClickListener {
val intent = Intent( val intent = Intent(
...@@ -45,12 +44,5 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() { ...@@ -45,12 +44,5 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() {
startActivity(intent) startActivity(intent)
} }
} }
private fun startNotification() {
val intent = Intent(this, NotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
} else {
startService(intent)
}
}
} }
\ No newline at end of file
...@@ -10,8 +10,6 @@ import android.util.Log ...@@ -10,8 +10,6 @@ import android.util.Log
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.test.easy.easycleanerjunk.databinding.ActivityLayoutSplashBinding import com.test.easy.easycleanerjunk.databinding.ActivityLayoutSplashBinding
import com.test.easy.easycleanerjunk.display.CloseNotificationReceiver
import com.test.easy.easycleanerjunk.display.NotificationService
import com.test.easy.easycleanerjunk.helps.BaseActivity import com.test.easy.easycleanerjunk.helps.BaseActivity
import com.test.easy.easycleanerjunk.helps.ConfigHelper import com.test.easy.easycleanerjunk.helps.ConfigHelper
import com.test.easy.easycleanerjunk.helps.LogEx import com.test.easy.easycleanerjunk.helps.LogEx
...@@ -72,12 +70,12 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(), ...@@ -72,12 +70,12 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
} }
private fun startNotification() { private fun startNotification() {
val intent = Intent(this, NotificationService::class.java) // val intent = Intent(this, NotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent) // startForegroundService(intent)
} else { // } else {
startService(intent) // startService(intent)
} // }
} }
override fun onProgressMax() { override fun onProgressMax() {
......
package com.test.easy.easycleanerjunk.display
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.test.easy.easycleanerjunk.helps.LogEx
class CloseNotificationReceiver : BroadcastReceiver() {
private val TAG = "CloseNotificationReceiver"
override fun onReceive(context: Context?, intent: Intent?) {
LogEx.logDebug(TAG, "onReceive intent.action=${intent?.action}")
//cancel事件,经过测试Intent.action这里无法传递参数
if (intent?.action == null) {
}
intent?.let {
val notificationId = it.getIntExtra("notificationId", -1)
LogEx.logDebug(TAG, "notificationId=$notificationId action=$action")
if (notificationId != -1 && it.action != "DELETE_NOTIFICATION") {
val notificationManager = context?.getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
notificationManager?.cancel(NotificationUtils.NOTIFICATION_TAG, notificationId)
}
}
}
companion object {
const val action = "com.file.notification.CloseNotificationReceiver"
}
}
package com.test.easy.easycleanerjunk.display
import android.app.Service
import android.content.Intent
import android.os.IBinder
class NotificationService : Service() {
companion object {
var isRunning = false
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (isRunning) {
stopSelf()
return START_NOT_STICKY
}
val notification = NotificationUtils.createPermanentNotification(applicationContext)
startForeground(1, notification)
return START_STICKY
}
override fun onBind(intent: Intent?): IBinder? {
return null
}
override fun onDestroy() {
isRunning = false
super.onDestroy()
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.display
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import com.test.easy.easycleanerjunk.R
import com.test.easy.easycleanerjunk.activity.ScanJunkActivity
import com.test.easy.easycleanerjunk.activity.home.NewMainActivity
import com.test.easy.easycleanerjunk.service.FlashlightService
object NotificationUtils {
const val NOTIFICATION_TAG = "SmartCleanNotification"
fun createPermanentNotification(context: Context): Notification {
Log.d(
"startForegroundService",
"Start foreground service."
)
val isOngoing = true //是否持续(为不消失的常驻通知)
val channelName = context.resources.getString(R.string.foreground_service_channel)
val channelId = "Service_Id"
val category = Notification.CATEGORY_SERVICE
val contentView = RemoteViews(context.packageName, R.layout.reminder_layout_notification_notify)
val expendView = RemoteViews(context.packageName, R.layout.reminder_layout_notification_big_notify)
val intent0 = Intent(context, ScanJunkActivity::class.java)
val pendingIntent0 =
PendingIntent.getActivity(context, 0, intent0, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_ll_clean, pendingIntent0)
expendView.setOnClickPendingIntent(R.id.id_ll_clean, pendingIntent0)
// val intent2 = Intent(context, ::class.java)
// val pendingIntent2 =
// PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_IMMUTABLE)
// contentView.setOnClickPendingIntent(R.id.id_battery, pendingIntent2)
// expendView.setOnClickPendingIntent(R.id.id_battery, pendingIntent2)
val intent3 = Intent()
val serviceComponent = ComponentName(context, FlashlightService::class.java)
intent3.component = serviceComponent
val pendingIntent3 =
PendingIntent.getService(context, 0, intent3, PendingIntent.FLAG_IMMUTABLE)
contentView.setOnClickPendingIntent(R.id.id_lighit, pendingIntent3)
expendView.setOnClickPendingIntent(R.id.id_lighit, pendingIntent3)
// val intent4 = Intent(context, ::class.java)
// val pendingIntent4 =
// PendingIntent.getActivity(context, 0, intent4, PendingIntent.FLAG_IMMUTABLE)
// contentView.setOnClickPendingIntent(R.id.id_app_manager, pendingIntent4)
// expendView.setOnClickPendingIntent(R.id.id_app_manager, pendingIntent4)
val nfIntent = Intent(context, NewMainActivity::class.java)
val pendingIntent =
PendingIntent.getActivity(context, 0, nfIntent, PendingIntent.FLAG_IMMUTABLE)
val builder = NotificationCompat.Builder(context, channelId)
builder.setCustomContentView(contentView)
builder.setCustomBigContentView(expendView)
builder.setContentIntent(pendingIntent) //设置PendingIntent
builder.setSmallIcon(R.mipmap.logo) //设置状态栏内的小图标
builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE) //设置通知公开可见
builder.setOngoing(isOngoing) //设置持续(不消失的常驻通知)
// builder.setCategory(category) //设置类别
builder.setAutoCancel(false)
builder.setPriority(NotificationCompat.PRIORITY_MAX) //优先级为:重要通知
builder.setWhen(System.currentTimeMillis())
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)
}
val notification = builder.build()
return notification
}
}
package com.test.easy.easycleanerjunk.service
import android.app.Service
import android.content.Context
import android.content.Intent
import android.hardware.camera2.CameraAccessException
import android.hardware.camera2.CameraManager
import android.os.Build
import android.os.IBinder
import android.util.Log
class FlashlightService : Service() {
private var cameraManager: CameraManager? = null
private var flashlightOn = false
override fun onCreate() {
super.onCreate()
cameraManager = getSystemService(Context.CAMERA_SERVICE) as CameraManager?
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
try {
val cameraId = cameraManager!!.cameraIdList[0]
flashlightOn = if (flashlightOn) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
cameraManager!!.setTorchMode(cameraId, false)
}
false
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
cameraManager!!.setTorchMode(cameraId, true)
}
true
}
} catch (e: CameraAccessException) {
e.printStackTrace()
}
return START_NOT_STICKY
}
override fun onBind(p0: Intent?): IBinder? {
return null
}
}
\ 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