Skip to content

Commit 261914e

Browse files
committed
- Migrating to FCM
1 parent 1ce432c commit 261914e

11 files changed

+64
-84
lines changed

app/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 26
5-
buildToolsVersion '26.0.2'
4+
compileSdkVersion 27
65

76
defaultConfig {
87
applicationId "com.example.instabug"
98
minSdkVersion 15
10-
targetSdkVersion 26
9+
targetSdkVersion 27
1110
versionCode 1
1211
versionName "1.0"
1312
multiDexEnabled true
@@ -41,11 +40,13 @@ repositories {
4140

4241
dependencies {
4342
implementation fileTree(dir: 'libs', include: ['*.jar'])
44-
implementation 'com.android.support:multidex:1.0.2'
45-
implementation 'com.android.support:design:26.0.2'
46-
implementation 'com.android.support:appcompat-v7:26.0.2'
47-
// TODO if you use a lower version than 9.0.0 (min is 7.5.0) you should uncomment the exclude line to avoid errors
48-
implementation 'com.google.android.gms:play-services:11.4.2'
43+
implementation 'com.android.support:multidex:1.0.3'
44+
implementation "com.android.support:design:$rootProject.ext.androidSupport"
45+
implementation "com.android.support:appcompat-v7:$rootProject.ext.androidSupport"
46+
47+
implementation 'com.google.firebase:firebase-core:16.0.0'
48+
implementation 'com.google.firebase:firebase-messaging:17.0.0'
49+
4950
// TODO add the following 2 lines if you exclude io.reactivex from Instabug
5051
// implementation 'io.reactivex:rxjava:1.0.13'
5152
// implementation 'io.reactivex:rxandroid:1.0.1'

app/proguard-rules.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
1616
# public *;
1717
#}
18-
-dontwarn butterknife.internal.**
18+
-dontwarn butterknife.internal.**
19+
-keep class com.google.firebase.provider.FirebaseInitProvider
20+
-keep class com.example.instabug.**

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,21 @@
4646
android:name="com.google.android.geo.API_KEY"
4747
android:value="AIzaSyD1NsFNyD12H_4lzgzth7lUxUAbZzyKEL4" />
4848

49-
<receiver
50-
android:name="com.google.android.gms.gcm.GcmReceiver"
51-
android:exported="true"
52-
android:permission="com.google.android.c2dm.permission.SEND">
53-
<intent-filter>
54-
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
55-
<category android:name="com.example.instabug" />
56-
</intent-filter>
57-
</receiver>
58-
5949
<service
60-
android:name="com.example.instabug.gcm.InstabugGCMListenerService"
50+
android:name="com.example.instabug.fcm.InstabugFCMListenerService"
6151
android:exported="false">
6252
<intent-filter>
6353
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
6454
</intent-filter>
6555
</service>
56+
6657
<service
67-
android:name="com.example.instabug.gcm.InstabugInstanceIDListenerService"
58+
android:name="com.example.instabug.fcm.InstabugInstanceIDListenerService"
6859
android:exported="false">
6960
<intent-filter>
7061
<action android:name="com.google.android.gms.iid.InstanceID" />
7162
</intent-filter>
7263
</service>
73-
<service android:name="com.example.instabug.gcm.RegistrationIntentService"/>
64+
<service android:name="com.example.instabug.fcm.RegistrationIntentService"/>
7465
</application>
7566
</manifest>

app/src/main/java/com/example/instabug/SampleApplication.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
package com.example.instabug;
22

33
import android.app.Application;
4+
import android.content.Context;
45
import android.support.multidex.MultiDex;
56

67
import com.instabug.library.Instabug;
78
import com.instabug.library.InstabugColorTheme;
89
import com.instabug.library.InstabugCustomTextPlaceHolder;
9-
import com.instabug.library.bugreporting.model.ReportCategory;
1010
import com.instabug.library.internal.module.InstabugLocale;
1111
import com.instabug.library.invocation.InstabugInvocationEvent;
1212
import com.instabug.library.ui.onboarding.WelcomeMessage;
1313

14-
import java.util.ArrayList;
1514
import java.util.Locale;
1615

1716

1817
public class SampleApplication extends Application {
18+
@Override
19+
protected void attachBaseContext(Context base) {
20+
super.attachBaseContext(base);
21+
MultiDex.install(this);
22+
}
23+
1924
@Override
2025
public void onCreate() {
2126
super.onCreate();
22-
MultiDex.install(this);
2327

2428
//initialing instabug
2529
new Instabug.Builder(this, "48ad905e141bc665d064945f423aa414")

app/src/main/java/com/example/instabug/gcm/InstabugGCMListenerService.java renamed to app/src/main/java/com/example/instabug/fcm/InstabugFCMListenerService.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package com.example.instabug.gcm;
1+
package com.example.instabug.fcm;
22

33
import com.example.instabug.R;
44
import com.example.instabug.ui.activities.MainActivity;
5-
import com.google.android.gms.gcm.GcmListenerService;
5+
import com.google.firebase.messaging.FirebaseMessagingService;
6+
import com.google.firebase.messaging.RemoteMessage;
67
import com.instabug.library.Instabug;
78

89
import android.app.NotificationManager;
@@ -11,44 +12,37 @@
1112
import android.content.Intent;
1213
import android.media.RingtoneManager;
1314
import android.net.Uri;
14-
import android.os.Bundle;
1515
import android.support.v4.app.NotificationCompat;
1616
import android.util.Log;
1717

1818
/**
1919
* Created by vezikon on 6/27/16.
2020
*/
21-
public class InstabugGCMListenerService extends GcmListenerService {
22-
private static final String TAG = "InstabugGCMListenerService";
21+
public class InstabugFCMListenerService extends FirebaseMessagingService {
22+
private static final String TAG = "FCMListenerService";
2323

24-
/**
25-
* Called when message is received.
26-
*
27-
* @param from SenderID of the sender.
28-
* @param data Data bundle containing message data as key/value pairs.
29-
* For Set of keys use data.keySet().
30-
*/
31-
// [START receive_message]
3224
@Override
33-
public void onMessageReceived(String from, Bundle data) {
34-
String message = data.getString("message");
35-
Log.d(TAG, "From: " + from);
25+
public void onMessageReceived(RemoteMessage remoteMessage) {
26+
super.onMessageReceived(remoteMessage);
27+
28+
String message = remoteMessage.getData().get("message");
29+
Log.d(TAG, "From: " + remoteMessage.getFrom());
3630
Log.d(TAG, "Message: " + message);
3731

3832
//Check first if notification related to Instabug or not
39-
if(Instabug.isInstabugNotification(data)){
33+
if (Instabug.isInstabugNotification(remoteMessage.getData())) {
4034
//Shown notification related to Instabug
41-
Instabug.showNotification(data);
42-
}else {
35+
Instabug.showNotification(remoteMessage.getData());
36+
} else {
4337
sendNotification(message);
4438
}
39+
4540
}
46-
// [END receive_message]
4741

4842
/**
49-
* Create and show a simple notification containing the received GCM message.
43+
* Create and show a simple notification containing the received FCM message.
5044
*
51-
* @param message GCM message received.
45+
* @param message FCM message received.
5246
*/
5347
private void sendNotification(String message) {
5448
Intent intent = new Intent(this, MainActivity.class);
@@ -59,7 +53,7 @@ private void sendNotification(String message) {
5953
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
6054
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
6155
.setSmallIcon(R.mipmap.ic_launcher)
62-
.setContentTitle("GCM Message")
56+
.setContentTitle("FCM Message")
6357
.setContentText(message)
6458
.setAutoCancel(true)
6559
.setSound(defaultSoundUri)

app/src/main/java/com/example/instabug/gcm/InstabugInstanceIDListenerService.java renamed to app/src/main/java/com/example/instabug/fcm/InstabugInstanceIDListenerService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package com.example.instabug.gcm;
1+
package com.example.instabug.fcm;
22

33
import android.content.Intent;
44

5-
import com.google.android.gms.iid.InstanceIDListenerService;
5+
import com.google.firebase.iid.FirebaseInstanceIdService;
66

77
/**
88
* Created by vezikon on 6/27/16.
99
*/
10-
public class InstabugInstanceIDListenerService extends InstanceIDListenerService {
10+
public class InstabugInstanceIDListenerService extends FirebaseInstanceIdService {
1111

1212
private static final String TAG = "InstabugInstanceIDLS";
1313

app/src/main/java/com/example/instabug/gcm/QuickstartPreferences.java renamed to app/src/main/java/com/example/instabug/fcm/QuickstartPreferences.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.instabug.gcm;
1+
package com.example.instabug.fcm;
22

33
/**
44
* Created by vezikon on 6/27/16.

app/src/main/java/com/example/instabug/gcm/RegistrationIntentService.java renamed to app/src/main/java/com/example/instabug/fcm/RegistrationIntentService.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
package com.example.instabug.gcm;
1+
package com.example.instabug.fcm;
22

33
import android.app.IntentService;
44
import android.content.Intent;
55
import android.content.SharedPreferences;
66
import android.preference.PreferenceManager;
77
import android.support.v4.content.LocalBroadcastManager;
88
import android.util.Log;
9-
import com.google.android.gms.gcm.GoogleCloudMessaging;
10-
import com.google.android.gms.iid.InstanceID;
9+
import com.google.firebase.iid.FirebaseInstanceId;
1110
import com.instabug.library.Instabug;
1211

1312

@@ -28,17 +27,15 @@ protected void onHandleIntent(Intent intent) {
2827
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
2928

3029
try {
31-
// [START register_for_gcm]
30+
// [START register_for_fcm]
3231
// Initially this call goes out to the network to retrieve the token, subsequent calls
3332
// are local.
34-
// R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
33+
// R.string.fcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
3534
// See https://developers.google.com/cloud-messaging/android/start for details on this file.
3635
// [START get_token]
37-
InstanceID instanceID = InstanceID.getInstance(this);
38-
String token = instanceID.getToken(QuickstartPreferences.SENDER_ID,
39-
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
36+
String token = FirebaseInstanceId.getInstance().getToken();
4037
// [END get_token]
41-
Log.i(TAG, "GCM Registration Token: " + token);
38+
Log.i(TAG, "FCM Registration Token: " + token);
4239

4340
// TODO: Implement this method to send any registration to your app's servers.
4441
sendRegistrationToServer(token);
@@ -47,7 +44,7 @@ protected void onHandleIntent(Intent intent) {
4744
// sent to your server. If the boolean is false, send the token to your server,
4845
// otherwise your server should have already received the token.
4946
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
50-
// [END register_for_gcm]
47+
// [END register_for_fcm]
5148
} catch (Exception e) {
5249
Log.d(TAG, "Failed to complete token refresh", e);
5350
// If an exception happens while fetching the new token or updating our registration data
@@ -62,7 +59,7 @@ protected void onHandleIntent(Intent intent) {
6259
/**
6360
* Persist registration to third-party servers.
6461
*
65-
* Modify this method to associate the user's GCM registration token with any server-side account
62+
* Modify this method to associate the user's FCM registration token with any server-side account
6663
* maintained by your application.
6764
*
6865
* @param token The new token.

app/src/main/java/com/example/instabug/ui/activities/MainActivity.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,17 @@
33
import android.app.AlertDialog;
44
import android.content.DialogInterface;
55
import android.content.Intent;
6-
import android.graphics.Color;
76
import android.net.Uri;
87
import android.os.AsyncTask;
98
import android.os.Bundle;
10-
import android.support.design.widget.NavigationView;
11-
import android.support.v4.view.GravityCompat;
12-
import android.support.v4.widget.DrawerLayout;
13-
import android.support.v7.app.ActionBarDrawerToggle;
149
import android.support.v7.widget.Toolbar;
1510
import android.util.Log;
16-
import android.view.Menu;
17-
import android.view.MenuItem;
1811
import android.view.View;
19-
import android.widget.AdapterView;
20-
import android.widget.ArrayAdapter;
21-
import android.widget.ImageView;
22-
import android.widget.Spinner;
23-
import android.widget.Toast;
2412

2513
import com.example.instabug.BaseActivity;
2614
import com.example.instabug.R;
27-
import com.example.instabug.gcm.RegistrationIntentService;
15+
import com.example.instabug.fcm.RegistrationIntentService;
2816
import com.instabug.library.Instabug;
29-
import com.instabug.library.invocation.InstabugInvocationMode;
3017
import com.instabug.library.logging.InstabugLog;
3118
import com.instabug.library.logging.InstabugNetworkLog;
3219
import com.instabug.library.ui.onboarding.WelcomeMessage;
@@ -41,7 +28,6 @@
4128
import java.io.OutputStreamWriter;
4229
import java.net.HttpURLConnection;
4330
import java.net.URL;
44-
import java.util.Set;
4531

4632
public class MainActivity extends BaseActivity {
4733

@@ -53,16 +39,16 @@ protected void onCreate(Bundle savedInstanceState) {
5339
//Instabug logs
5440
InstabugLog.d("MainActivity - Created");
5541

56-
registerGCM();
42+
registerFCM();
5743

5844
Toolbar toolbar = findViewById(R.id.toolbar);
5945
setSupportActionBar(toolbar);
6046

6147
doNetworkRequest();
6248
}
6349

64-
private void registerGCM() {
65-
// Start IntentService to register this application with GCM.
50+
private void registerFCM() {
51+
// Start IntentService to register this application with FCM.
6652
Intent intent = new Intent(this, RegistrationIntentService.class);
6753
startService(intent);
6854
}

build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
9+
classpath 'com.android.tools.build:gradle:3.1.2'
1010
}
1111
}
1212

@@ -19,3 +19,8 @@ allprojects {
1919
task clean(type: Delete) {
2020
delete rootProject.buildDir
2121
}
22+
23+
24+
ext {
25+
androidSupport = "27.1.1"
26+
}

0 commit comments

Comments
 (0)