Commit 512d392a authored by wanglei's avatar wanglei

...fcm

parent df6e2756
...@@ -13,7 +13,7 @@ android { ...@@ -13,7 +13,7 @@ android {
compileSdk = 34 compileSdk = 34
defaultConfig { defaultConfig {
applicationId = "com.base.locationsharewhite" applicationId = "com.tool.advanced.cleaner"
minSdk = 24 minSdk = 24
targetSdk = 34 targetSdk = 34
versionCode = 1 versionCode = 1
......
{ {
"project_info": { "project_info": {
"project_number": "953792647345", "project_number": "755421476297",
"project_id": "pdf-test-d0ae7", "project_id": "comtooladvancedcleaner",
"storage_bucket": "pdf-test-d0ae7.appspot.com" "storage_bucket": "comtooladvancedcleaner.firebasestorage.app"
}, },
"client": [ "client": [
{ {
"client_info": { "client_info": {
"mobilesdk_app_id": "1:953792647345:android:c5234e8bfc859f8b20d290", "mobilesdk_app_id": "1:755421476297:android:c66d8129d83b17e8af6418",
"android_client_info": { "android_client_info": {
"package_name": "com.base.locationsharewhite" "package_name": "com.tool.advanced.cleaner"
} }
}, },
"oauth_client": [], "oauth_client": [],
"api_key": [ "api_key": [
{ {
"current_key": "AIzaSyBT6B1oPmkojGX0TgBOI9bDkx5pdEFXWoo" "current_key": "AIzaSyAhCB4trMZPymkWCNl_m-bFGPpASG6bsQI"
} }
], ],
"services": { "services": {
......
...@@ -131,7 +131,7 @@ ...@@ -131,7 +131,7 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" /> <action android:name="com.google.firebase.MESSAGING_EVENT" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="confine.scream" /> <category android:name="com.tool.advanced.cleaner" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver <receiver
......
package com.base.locationsharewhite.fcm
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import com.base.locationsharewhite.helper.EventUtils import com.base.locationsharewhite.helper.EventUtils
...@@ -11,6 +13,7 @@ import com.google.firebase.messaging.FirebaseMessaging ...@@ -11,6 +13,7 @@ import com.google.firebase.messaging.FirebaseMessaging
import org.json.JSONObject import org.json.JSONObject
object FCMManager { object FCMManager {
fun initFirebase(context: Context?) { fun initFirebase(context: Context?) {
FirebaseApp.initializeApp(context!!) FirebaseApp.initializeApp(context!!)
LogEx.logDebug("initFirebase", "initFirebase") LogEx.logDebug("initFirebase", "initFirebase")
...@@ -40,6 +43,9 @@ object FCMManager { ...@@ -40,6 +43,9 @@ object FCMManager {
} }
} }
/**
* 有vpn有google商店才能获取
*/
private fun getToken() { private fun getToken() {
FirebaseMessaging.getInstance().token FirebaseMessaging.getInstance().token
.addOnCompleteListener(object : OnCompleteListener<String> { .addOnCompleteListener(object : OnCompleteListener<String> {
...@@ -59,7 +65,7 @@ object FCMManager { ...@@ -59,7 +65,7 @@ object FCMManager {
AppPreferences.getInstance().put("token", token) AppPreferences.getInstance().put("token", token)
// Handle new token // Handle new token
Log.d("FCM", "FCM Registration Token: $token") LogEx.logDebug("FCM", "FCM Registration Token: $token")
} }
}) })
} }
......
package com.base.locationsharewhite.fcm; package com.base.locationsharewhite.fcm
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver
import android.content.Context; import android.content.Context
import android.content.Intent; import android.content.Intent
import com.applovin.sdk.AppLovinSdkUtils.runOnUiThread
import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.locationsharewhite.helper.EventUtils.event
import com.base.locationsharewhite.helper.MyApplication
import com.base.locationsharewhite.utils.LogEx
import com.base.locationsharewhite.utils.LogEx.logDebug
import com.base.locationsharewhite.utils.ToastUtils.toast
import com.base.locationsharewhite.helper.EventUtils; class FcmReceiver : BroadcastReceiver() {
import com.base.locationsharewhite.utils.LogEx; private val TAG = "FcmReceiver"
override fun onReceive(context: Context, intent: Intent) {
LogEx.logDebug("FCM", "FcmReceiver")
event("FCM_Received", null, null, false)
public class FcmReceiver extends BroadcastReceiver { sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_FCM, null)
private String TAG = "FcmReceiver";
@Override if (BuildConfig.DEBUG) {
public void onReceive(Context context, Intent intent) { runOnUiThread {
LogEx.INSTANCE.logDebug(TAG, "onReceive", false); runCatching {
EventUtils.INSTANCE.event("FCM_Received", null, null, false); MyApplication.appContext.toast("FcmReceiver fcm")
}
NotificationUiUtil.INSTANCE.sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_FCM, null); }
}
} }
} }
package com.base.locationsharewhite.fcm; package com.base.locationsharewhite.fcm
import android.annotation.SuppressLint; import android.annotation.SuppressLint
import com.applovin.sdk.AppLovinSdkUtils.runOnUiThread
import androidx.annotation.NonNull; import com.base.locationsharewhite.BuildConfig
import com.base.locationsharewhite.fcm.NotificationUiUtil.sendNotificationIfCan
import com.base.locationsharewhite.helper.EventUtils; import com.base.locationsharewhite.helper.EventUtils.event
import com.base.locationsharewhite.utils.LogEx; import com.base.locationsharewhite.helper.MyApplication
import com.google.firebase.messaging.FirebaseMessagingService; import com.base.locationsharewhite.utils.LogEx
import com.google.firebase.messaging.RemoteMessage; import com.base.locationsharewhite.utils.ToastUtils.toast
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import org.json.JSONException
import org.json.JSONObject
@SuppressLint("MissingFirebaseInstanceTokenRefresh") @SuppressLint("MissingFirebaseInstanceTokenRefresh")
public class MessagingService extends FirebaseMessagingService { class MessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
private static final String TAG = "MessagingService"; super.onMessageReceived(remoteMessage)
val id = remoteMessage.messageId
@Override val ext = JSONObject()
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) { try {
super.onMessageReceived(remoteMessage); ext.put("getMessageType", remoteMessage.messageType)
LogEx.INSTANCE.logDebug(TAG, "onMessageReceived", false); ext.put("getData", remoteMessage.data)
EventUtils.INSTANCE.event("FCM_Received", null, null, false); ext.put("getCollapseKey", remoteMessage.collapseKey)
ext.put("getFrom", remoteMessage.from)
NotificationUiUtil.INSTANCE.sendNotificationIfCan(this, PopupConstObject.POPUP_WHERE_FCM, null); ext.put("getPriority", remoteMessage.priority)
ext.put("getSenderId", remoteMessage.senderId)
ext.put("getSentTime", remoteMessage.sentTime)
} catch (e: JSONException) {
event("FCM_Received_Error", id, ext, false)
throw RuntimeException(e)
} finally {
}
event("FCM_Received", id, ext, false)
LogEx.logDebug("FCM", "MessagingService")
sendNotificationIfCan(this, PopupConstObject.POPUP_WHERE_FCM, null)
if (BuildConfig.DEBUG) {
runOnUiThread {
runCatching {
MyApplication.appContext.toast("MessagingService fcm")
}
}
}
} }
companion object {
private const val TAG = "MessagingService"
}
} }
\ No newline at end of file
package com.base.locationsharewhite.helper package com.base.locationsharewhite.helper
import FCMManager import com.base.locationsharewhite.fcm.FCMManager
import android.app.Activity import android.app.Activity
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
...@@ -21,6 +21,7 @@ import com.base.locationsharewhite.service.StayJobService.Companion.startJob ...@@ -21,6 +21,7 @@ import com.base.locationsharewhite.service.StayJobService.Companion.startJob
import com.base.locationsharewhite.ui.splash.SplashActivity import com.base.locationsharewhite.ui.splash.SplashActivity
import com.base.locationsharewhite.utils.AppPreferences import com.base.locationsharewhite.utils.AppPreferences
import com.base.locationsharewhite.utils.LogEx import com.base.locationsharewhite.utils.LogEx
import com.facebook.FacebookSdk
import com.hjq.language.MultiLanguages import com.hjq.language.MultiLanguages
import com.hjq.language.OnLanguageListener import com.hjq.language.OnLanguageListener
import java.util.Locale import java.util.Locale
...@@ -81,9 +82,10 @@ class MyApplication : Application() { ...@@ -81,9 +82,10 @@ class MyApplication : Application() {
} }
private fun initApp() { private fun initApp() {
// FacebookSdk.sdkInitialize(applicationContext) FacebookSdk.sdkInitialize(applicationContext)
val token = AppPreferences.getInstance().getString("token", "")
val topic = AppConfig.packageName + "_push" val topic = AppConfig.packageName + "_push"
LogEx.logDebug(TAG, "topic=${topic}") LogEx.logDebug(TAG, "topic=${topic} token=$token")
FCMManager.initFirebase(this) FCMManager.initFirebase(this)
FCMManager.subscribeToTopic(topic) FCMManager.subscribeToTopic(topic)
InstallHelps.init() InstallHelps.init()
......
...@@ -94,7 +94,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback { ...@@ -94,7 +94,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnMapReadyCallback {
mainPresenter.startLocationJob(lifecycleScope) mainPresenter.startLocationJob(lifecycleScope)
showAllowAllTimeDialog() showAllowAllTimeDialog()
changeLanguage(this) // changeLanguage(this)
} }
private fun showNotificationDialog() { private fun showNotificationDialog() {
......
...@@ -61,7 +61,7 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() { ...@@ -61,7 +61,7 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() {
override fun onResumeOneShoot() { override fun onResumeOneShoot() {
super.onResumeOneShoot() super.onResumeOneShoot()
changeLanguage(this) // changeLanguage(this)
} }
override fun onResume() { override fun onResume() {
......
...@@ -99,7 +99,8 @@ ...@@ -99,7 +99,8 @@
android:layout_marginTop="18dp" android:layout_marginTop="18dp"
android:background="?android:attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true"> android:focusable="true"
android:visibility="gone">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
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