Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
A
appzxhy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
appzxhy
Commits
c3391b64
Commit
c3391b64
authored
Dec 27, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...gid
parent
b35986a1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
6 deletions
+101
-6
README.md
README.md
+10
-1
MyApplication.kt
app/src/main/java/com/base/appzxhy/MyApplication.kt
+18
-5
FCMManager.kt
app/src/main/java/com/base/appzxhy/fcm/FCMManager.kt
+73
-0
No files found.
README.md
View file @
c3391b64
# appzxhy
用来快速搭建项目滴
\ No newline at end of file
用来快速搭建项目滴
# 商业化
## Application中
1.
公共参数 uuid 和 gid
2.
初始化广告
3.
初始化Facebook
4.
FCM上报topic和token
app/src/main/java/com/base/appzxhy/MyApplication.kt
View file @
c3391b64
...
...
@@ -6,11 +6,15 @@ import android.content.Context
import
android.os.Bundle
import
android.text.TextUtils
import
android.util.Log
import
com.base.appzxhy.ads.AdsMgr
import
com.base.appzxhy.bean.ConstObject.appLanguageCountrySp
import
com.base.appzxhy.bean.ConstObject.appLanguageSp
import
com.base.appzxhy.fcm.FCMManager
import
com.base.appzxhy.utils.ActivityManagerUtils
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.LogEx
import
com.facebook.FacebookSdk
import
com.google.android.gms.ads.identifier.AdvertisingIdClient
import
com.hjq.language.MultiLanguages
import
com.hjq.language.OnLanguageListener
import
java.util.Locale
...
...
@@ -44,6 +48,7 @@ class MyApplication : Application() {
super
.
onCreate
()
appContext
=
this
initUUid
()
initGid
()
initApp
()
// 初始化语种切换框架
...
...
@@ -66,6 +71,14 @@ class MyApplication : Application() {
})
}
private
fun
initGid
()
{
Thread
{
val
info
:
AdvertisingIdClient
.
Info
=
AdvertisingIdClient
.
getAdvertisingIdInfo
(
applicationContext
)
val
advertisingId
=
info
.
id
AppPreferences
.
getInstance
().
put
(
"gid"
,
advertisingId
)
}.
start
()
}
override
fun
attachBaseContext
(
base
:
Context
?)
{
super
.
attachBaseContext
(
MultiLanguages
.
attach
(
base
))
}
...
...
@@ -82,14 +95,14 @@ class MyApplication : Application() {
private
fun
initApp
()
{
//初始化广告相关业务
// com.base.appzxhy.ads.
AdsMgr.init(appContext)
AdsMgr
.
init
(
appContext
)
//
FacebookSdk.sdkInitialize(applicationContext)
FacebookSdk
.
sdkInitialize
(
applicationContext
)
// val token = AppPreferences.getInstance().getString("token", "")
// val topic = AppConfig.packageName
+ "_push"
val
topic
=
GlobalConfig
.
PACKAGE_NAME
+
"_push"
// LogEx.logDebug(TAG, "topic=${topic} token=$token")
//
FCMManager.initFirebase(this)
//
FCMManager.subscribeToTopic(topic)
FCMManager
.
initFirebase
(
this
)
FCMManager
.
subscribeToTopic
(
topic
)
// initConfig()
//
...
...
app/src/main/java/com/base/appzxhy/fcm/FCMManager.kt
0 → 100644
View file @
c3391b64
package
com.base.appzxhy.fcm
import
android.content.Context
import
android.util.Log
import
com.base.appzxhy.helper.EventUtils.event
import
com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.LogEx
import
com.google.android.gms.tasks.OnCompleteListener
import
com.google.android.gms.tasks.Task
import
com.google.firebase.FirebaseApp
import
com.google.firebase.messaging.FirebaseMessaging
import
org.json.JSONObject
object
FCMManager
{
fun
initFirebase
(
context
:
Context
?)
{
FirebaseApp
.
initializeApp
(
context
!!
)
LogEx
.
logDebug
(
"initFirebase"
,
"initFirebase"
)
getToken
()
}
fun
subscribeToTopic
(
topic
:
String
)
{
Log
.
e
(
"FCMUtil"
,
"subscribeToTopic"
)
FirebaseMessaging
.
getInstance
().
subscribeToTopic
(
topic
)
.
addOnCompleteListener
{
task
->
if
(
task
.
isSuccessful
)
{
getToken
()
Log
.
e
(
"FCMUtil"
,
"isSuccessful"
)
event
(
"FCM_Topic_$topic"
,
null
,
null
)
}
else
{
event
(
"FCM_Error"
,
"subscribeToTopic task.isSuccessful=${task.isSuccessful} "
,
null
)
}
}
}
fun
unsubscribeFromTopic
(
topic
:
String
?)
{
FirebaseMessaging
.
getInstance
().
unsubscribeFromTopic
(
topic
!!
)
.
addOnCompleteListener
{
task
->
if
(
task
.
isSuccessful
)
{
}
else
{
}
}
}
/**
* 有vpn有google商店才能获取
*/
private
fun
getToken
()
{
FirebaseMessaging
.
getInstance
().
token
.
addOnCompleteListener
(
object
:
OnCompleteListener
<
String
>
{
override
fun
onComplete
(
task
:
Task
<
String
>)
{
LogEx
.
logDebug
(
"FCM"
,
"onComplete ${task.isSuccessful}"
)
if
(!
task
.
isSuccessful
)
{
Log
.
e
(
"FCM"
,
"Fetching FCM registration token failed"
,
task
.
exception
)
return
}
// Get new FCM registration token
val
token
:
String
=
task
.
result
LogEx
.
logDebug
(
"FCM"
,
"token=$token"
)
val
json
=
JSONObject
()
json
.
put
(
"token"
,
token
)
event
(
"fcm_message_received"
,
ext
=
json
)
AppPreferences
.
getInstance
().
put
(
"token"
,
token
)
// Handle new token
LogEx
.
logDebug
(
"FCM"
,
"FCM Registration Token: $token"
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment