Skip to content

Commit a003653

Browse files
author
Ahmad Idrees
committed
fcm class update
1 parent ab62b61 commit a003653

File tree

3 files changed

+139
-26
lines changed

3 files changed

+139
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Do not forget to add internet permission in manifest if already not present
1616
```xml
1717
<uses-permission android:name="android.permission.INTERNET" />
1818
```
19+
Create Firebase project, add you application ID init, download your google-services.json file and place it in app folder.
1920
### For FCM Notifications, initialize it in onCreate() Method of Application class :
2021
```kotlin
2122
val fcm = FirebaseFCM(this)

app/google-services.json

Lines changed: 123 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,149 @@
11
{
22
"project_info": {
3-
"project_number": "816941791543",
4-
"project_id": "newone-33895",
5-
"storage_bucket": "newone-33895.appspot.com"
3+
"project_number": "744390342276",
4+
"project_id": "fir-e967c",
5+
"storage_bucket": "fir-e967c.appspot.com"
66
},
77
"client": [
88
{
99
"client_info": {
10-
"mobilesdk_app_id": "1:816941791543:android:57ade9d363823c4c2902b2",
10+
"mobilesdk_app_id": "1:744390342276:android:ac69594aa48e365aee34d1",
1111
"android_client_info": {
1212
"package_name": "ai.bom.firebase"
1313
}
1414
},
1515
"oauth_client": [
1616
{
17-
"client_id": "816941791543-mv4km02uaquvd4t4n424h5mbcr8smkla.apps.googleusercontent.com",
17+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
1818
"client_type": 3
1919
}
2020
],
2121
"api_key": [
2222
{
23-
"current_key": "AIzaSyB09QIqgLt95O5uQjyIk0duflBS_IwisUM"
23+
"current_key": "AIzaSyCIpEz4fDK_LI2FCj6eJvTY2jQme1dzzws"
2424
}
2525
],
2626
"services": {
2727
"appinvite_service": {
2828
"other_platform_oauth_client": [
2929
{
30-
"client_id": "816941791543-mv4km02uaquvd4t4n424h5mbcr8smkla.apps.googleusercontent.com",
30+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
31+
"client_type": 3
32+
}
33+
]
34+
}
35+
}
36+
},
37+
{
38+
"client_info": {
39+
"mobilesdk_app_id": "1:744390342276:android:d471528021ee286dee34d1",
40+
"android_client_info": {
41+
"package_name": "com.all.video.downloader.fast.downloading.video.saver.browser"
42+
}
43+
},
44+
"oauth_client": [
45+
{
46+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
47+
"client_type": 3
48+
}
49+
],
50+
"api_key": [
51+
{
52+
"current_key": "AIzaSyCIpEz4fDK_LI2FCj6eJvTY2jQme1dzzws"
53+
}
54+
],
55+
"services": {
56+
"appinvite_service": {
57+
"other_platform_oauth_client": [
58+
{
59+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
60+
"client_type": 3
61+
}
62+
]
63+
}
64+
}
65+
},
66+
{
67+
"client_info": {
68+
"mobilesdk_app_id": "1:744390342276:android:dbe485ec01889a00ee34d1",
69+
"android_client_info": {
70+
"package_name": "com.app.remoteconfigdemo"
71+
}
72+
},
73+
"oauth_client": [
74+
{
75+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
76+
"client_type": 3
77+
}
78+
],
79+
"api_key": [
80+
{
81+
"current_key": "AIzaSyCIpEz4fDK_LI2FCj6eJvTY2jQme1dzzws"
82+
}
83+
],
84+
"services": {
85+
"appinvite_service": {
86+
"other_platform_oauth_client": [
87+
{
88+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
89+
"client_type": 3
90+
}
91+
]
92+
}
93+
}
94+
},
95+
{
96+
"client_info": {
97+
"mobilesdk_app_id": "1:744390342276:android:e2fc5fdc69783cf9ee34d1",
98+
"android_client_info": {
99+
"package_name": "com.app.remoteconfigdemo.debug"
100+
}
101+
},
102+
"oauth_client": [
103+
{
104+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
105+
"client_type": 3
106+
}
107+
],
108+
"api_key": [
109+
{
110+
"current_key": "AIzaSyCIpEz4fDK_LI2FCj6eJvTY2jQme1dzzws"
111+
}
112+
],
113+
"services": {
114+
"appinvite_service": {
115+
"other_platform_oauth_client": [
116+
{
117+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
118+
"client_type": 3
119+
}
120+
]
121+
}
122+
}
123+
},
124+
{
125+
"client_info": {
126+
"mobilesdk_app_id": "1:744390342276:android:785eb52588d59bc7ee34d1",
127+
"android_client_info": {
128+
"package_name": "smart.app.lock.master.locker.private.pin.pattern.safe.secure"
129+
}
130+
},
131+
"oauth_client": [
132+
{
133+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
134+
"client_type": 3
135+
}
136+
],
137+
"api_key": [
138+
{
139+
"current_key": "AIzaSyCIpEz4fDK_LI2FCj6eJvTY2jQme1dzzws"
140+
}
141+
],
142+
"services": {
143+
"appinvite_service": {
144+
"other_platform_oauth_client": [
145+
{
146+
"client_id": "744390342276-juc53gc7jmnb4tvnturfoh9mveh0oacl.apps.googleusercontent.com",
31147
"client_type": 3
32148
}
33149
]

firebaseLib/src/main/java/ai/bom/firebase/lib/fcm/FirebaseMessagingService.kt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class FirebaseMessagingService : FirebaseMessagingService() {
3131
override fun onMessageReceived(remoteMessage: RemoteMessage) {
3232
Log.i(TAG, "onMessageReceived: ")
3333

34-
3534
//Data available
3635
if (remoteMessage.data.isNotEmpty()) {
3736
Log.d(TAG, "Message data payload: ${remoteMessage.data}")
@@ -45,12 +44,12 @@ class FirebaseMessagingService : FirebaseMessagingService() {
4544
val packageName = remoteMessage.data["app_url"]?.split("=")?.get(1)
4645

4746
//Check already installed app
48-
if (packageName != null) {
49-
val alreadyInstalled = isAppInstalled(packageName, this)
50-
if (alreadyInstalled) return
47+
if (!packageName.isNullOrEmpty()) {
48+
// val alreadyInstalled = isAppInstalled(packageName)
49+
// if (alreadyInstalled) return
5150

5251
//send notification
53-
if (icon == null || title == null || shortDesc == null) {
52+
if (icon.isNullOrEmpty() || title.isNullOrEmpty() || shortDesc.isNullOrEmpty()) {
5453
return
5554
} else {
5655
Handler(this.mainLooper).post {
@@ -70,26 +69,27 @@ class FirebaseMessagingService : FirebaseMessagingService() {
7069
longDesc: String?,
7170
storePackage: String
7271
) {
72+
val alreadyInstalled = isAppInstalled(storePackage)
73+
Log.i(TAG, "alreadyInstalled: $alreadyInstalled, $longDesc")
7374

74-
//Open PlayStore
75-
val intent = try {
75+
val intent = if (alreadyInstalled) {
76+
packageManager.getLaunchIntentForPackage(storePackage)
77+
} else try {
7678
Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$storePackage"))
7779
} catch (e: ActivityNotFoundException) {
7880
Intent(
7981
Intent.ACTION_VIEW,
8082
Uri.parse("https://play.google.com/store/apps/details?id=$storePackage")
8183
)
8284
}
83-
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
85+
intent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
8486
val pendingIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
8587
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
8688
} else {
8789
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
8890
}
8991

90-
Log.i(TAG, "longDesc: $longDesc")
91-
92-
//Make Remote Views For text
92+
//Remote Views
9393
val remoteViews = RemoteViews(packageName, R.layout.notification_view)
9494
remoteViews.setTextViewText(R.id.tv_title, title)
9595
remoteViews.setTextViewText(R.id.tv_short_desc, shortDesc)
@@ -126,27 +126,23 @@ class FirebaseMessagingService : FirebaseMessagingService() {
126126
//Set Images into remoteViews
127127
Picasso.get().load(icon)
128128
.into(remoteViews, R.id.iv_icon, notificationID, notificationBuilder.build())
129-
if (image != null) {
129+
if (!image.isNullOrEmpty()) {
130130
remoteViews.setViewVisibility(R.id.iv_feature, View.VISIBLE)
131131
Picasso.get().load(image)
132132
.into(remoteViews, R.id.iv_feature, notificationID, notificationBuilder.build())
133133
}
134134
}
135135

136-
private fun isAppInstalled(uri: String, context: Context): Boolean {
137-
val pm = context.packageManager
136+
private fun isAppInstalled(packageName: String): Boolean {
138137
return try {
139-
val applicationInfo = pm.getApplicationInfo(uri, 0)
138+
val applicationInfo = packageManager.getApplicationInfo(packageName, 0)
140139
applicationInfo.enabled
141140
} catch (e: PackageManager.NameNotFoundException) {
142141
false
143142
}
144143
}
145-
private val seed = AtomicInteger()
146144

147-
private fun getNextInt(): Int {
148-
return seed.incrementAndGet()
149-
}
145+
private fun getNextInt() = AtomicInteger().incrementAndGet()
150146

151147
override fun onNewToken(p0: String) {
152148

0 commit comments

Comments
 (0)