Skip to content

Commit f05265a

Browse files
committed
Use v2.5.0
1 parent 38417d9 commit f05265a

File tree

10 files changed

+249
-23
lines changed

10 files changed

+249
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Change Log
22
==========
33

4+
Version 2.5.0 *(2016-06-27)*
5+
----------------------------
6+
7+
* Exclude GCM from Instabug SDK
8+
* Add `Instabug.setPushNotificationRegistrationToken()`, `Instabug.isInstabugNotification()` and `Instabug.showNotification()` for supporting in-app messaging’s notifications for GCM and FCM.
9+
410
Version 2.4.0 *(2016-06-05)*
511
----------------------------
612

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,38 @@ Using Instabug is as easy as "Get ready, Get set, Go".
2828

2929
Grab your desired flavour via Gradle:
3030
```groovy
31-
compile 'com.instabug.library:instabug:2.4.0'
31+
compile 'com.instabug.library:instabug:2.5.0'
3232
```
3333
or
3434
```groovy
35-
compile 'com.instabug.library:instabugcompat:2.4.0'
35+
compile 'com.instabug.library:instabugcompat:2.5.0'
3636
```
3737
or
3838
```groovy
39-
compile 'com.instabug.library:instabugabs:2.4.0'
39+
compile 'com.instabug.library:instabugabs:2.5.0'
4040
```
4141
or via Maven: (if you're that kind of person :bowtie:)
4242
```xml
4343
<dependency>
4444
<groupId>com.instabug.library</groupId>
4545
<artifactId>instabug</artifactId>
46-
<version>2.3.3</version>
46+
<version>2.5.0</version>
4747
</dependency>
4848
```
4949
or
5050
```xml
5151
<dependency>
5252
<groupId>com.instabug.library</groupId>
5353
<artifactId>instabugcompat</artifactId>
54-
<version>2.3.3</version>
54+
<version>2.5.0</version>
5555
</dependency>
5656
```
5757
or
5858
```xml
5959
<dependency>
6060
<groupId>com.instabug.library</groupId>
6161
<artifactId>instabugabs</artifactId>
62-
<version>2.3.3</version>
62+
<version>2.5.0</version>
6363
</dependency>
6464
```
6565

app/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,27 @@ repositories {
2727
}
2828
}
2929

30+
3031
dependencies {
3132
compile fileTree(dir: 'libs', include: ['*.jar'])
3233
testCompile 'junit:junit:4.12'
3334
compile 'com.android.support:multidex:1.0.1'
3435
compile 'com.jakewharton:butterknife:7.0.1'
3536
compile 'com.android.support:design:23.2.0'
3637
compile 'com.android.support:appcompat-v7:23.2.0'
37-
// TODO if you use a lower version than 8.4.0 (min is 7.5.0) you should uncomment the exclude line to avoid errors
38+
// 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
3839
compile 'com.google.android.gms:play-services:9.0.0'
3940
// TODO add the following 2 lines if you exclude io.reactivex from Instabug
4041
// compile 'io.reactivex:rxjava:1.0.13'
4142
// compile 'io.reactivex:rxandroid:1.0.1'
42-
compile('com.instabug.library:instabug:2.4.0') {
43+
compile('com.instabug.library:instabug:2.5.0') {
4344
// TODO uncomment this line to exclude RxJava from Instabug and use your own version
4445
// exclude group: 'io.reactivex'
4546

4647
exclude group: 'com.android.support'
4748
// TODO uncomment next line if you're facing compilation issue in build.gradle about gms different versions
4849
// exclude group: 'com.google.android.gms'
4950
}
51+
52+
5053
}

app/src/main/AndroidManifest.xml

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest
3-
package="com.example.instabug"
4-
xmlns:android="http://schemas.android.com/apk/res/android"
5-
xmlns:tools="http://schemas.android.com/tools">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.example.instabug">
5+
6+
<uses-permission android:name="android.permission.WAKE_LOCK" />
7+
8+
<permission
9+
android:name="com.example.instabug.permission.C2D_MESSAGE"
10+
android:protectionLevel="signature" />
11+
<uses-permission android:name="com.example.instabug.permission.C2D_MESSAGE" />
612

713
<!-- TODO Deny RECORD_AUDIO permission from Instabug -->
814
<uses-permission
915
android:name="android.permission.RECORD_AUDIO"
10-
tools:node="remove"/>
16+
tools:node="remove" />
1117

1218
<uses-feature
1319
android:glEsVersion="0x00020000"
14-
android:required="true"/>
20+
android:required="true" />
1521

1622
<application
1723
android:name=".SampleApplication"
@@ -26,20 +32,46 @@
2632
android:label="@string/app_name"
2733
android:theme="@style/AppTheme.NoActionBar">
2834
<intent-filter>
29-
<action android:name="android.intent.action.MAIN"/>
30-
<category android:name="android.intent.category.LAUNCHER"/>
35+
<action android:name="android.intent.action.MAIN" />
36+
<category android:name="android.intent.category.LAUNCHER" />
3137
</intent-filter>
3238
</activity>
3339

34-
<activity android:name=".ui.activities.GoogleMapsActivity"/>
40+
<activity android:name=".ui.activities.GoogleMapsActivity" />
3541

3642
<meta-data
3743
android:name="com.google.android.gms.version"
38-
android:value="@integer/google_play_services_version"/>
44+
android:value="@integer/google_play_services_version" />
3945
<meta-data
4046
android:name="com.google.android.geo.API_KEY"
41-
android:value="AIzaSyD1NsFNyD12H_4lzgzth7lUxUAbZzyKEL4"/>
47+
android:value="AIzaSyD1NsFNyD12H_4lzgzth7lUxUAbZzyKEL4" />
48+
49+
<activity android:name=".ui.activities.OpenGLActivity" />
50+
51+
<receiver
52+
android:name="com.google.android.gms.gcm.GcmReceiver"
53+
android:exported="true"
54+
android:permission="com.google.android.c2dm.permission.SEND">
55+
<intent-filter>
56+
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
57+
<category android:name="com.example.instabug" />
58+
</intent-filter>
59+
</receiver>
4260

43-
<activity android:name=".ui.activities.OpenGLActivity"/>
61+
<service
62+
android:name=".gcm.InstabugGCMListenerService"
63+
android:exported="false">
64+
<intent-filter>
65+
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
66+
</intent-filter>
67+
</service>
68+
<service
69+
android:name="gcm.InstabugGCMListenerService"
70+
android:exported="false">
71+
<intent-filter>
72+
<action android:name="com.google.android.gms.iid.InstanceID" />
73+
</intent-filter>
74+
</service>
75+
<service android:name=".gcm.RegistrationIntentService"/>
4476
</application>
4577
</manifest>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.example.instabug.gcm;
2+
3+
import com.example.instabug.R;
4+
import com.example.instabug.ui.activities.MainActivity;
5+
import com.google.android.gms.gcm.GcmListenerService;
6+
import com.instabug.library.Instabug;
7+
8+
import android.app.NotificationManager;
9+
import android.app.PendingIntent;
10+
import android.content.Context;
11+
import android.content.Intent;
12+
import android.media.RingtoneManager;
13+
import android.net.Uri;
14+
import android.os.Bundle;
15+
import android.support.v4.app.NotificationCompat;
16+
import android.util.Log;
17+
18+
/**
19+
* Created by vezikon on 6/27/16.
20+
*/
21+
public class InstabugGCMListenerService extends GcmListenerService {
22+
private static final String TAG = "InstabugGCMListenerService";
23+
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]
32+
@Override
33+
public void onMessageReceived(String from, Bundle data) {
34+
String message = data.getString("message");
35+
Log.d(TAG, "From: " + from);
36+
Log.d(TAG, "Message: " + message);
37+
38+
//Check first if notification related to Instabug or not
39+
if(Instabug.isInstabugNotification(data)){
40+
//Shown notification related to Instabug
41+
Instabug.showNotification(data);
42+
}else {
43+
sendNotification(message);
44+
}
45+
}
46+
// [END receive_message]
47+
48+
/**
49+
* Create and show a simple notification containing the received GCM message.
50+
*
51+
* @param message GCM message received.
52+
*/
53+
private void sendNotification(String message) {
54+
Intent intent = new Intent(this, MainActivity.class);
55+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
56+
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
57+
PendingIntent.FLAG_ONE_SHOT);
58+
59+
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
60+
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
61+
.setSmallIcon(R.mipmap.ic_launcher)
62+
.setContentTitle("GCM Message")
63+
.setContentText(message)
64+
.setAutoCancel(true)
65+
.setSound(defaultSoundUri)
66+
.setContentIntent(pendingIntent);
67+
68+
NotificationManager notificationManager =
69+
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
70+
71+
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
72+
}
73+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.example.instabug.gcm;
2+
3+
import android.content.Intent;
4+
5+
import com.google.android.gms.iid.InstanceIDListenerService;
6+
7+
/**
8+
* Created by vezikon on 6/27/16.
9+
*/
10+
public class InstabugInstanceIDListenerService extends InstanceIDListenerService {
11+
12+
private static final String TAG = "InstabugInstanceIDLS";
13+
14+
/**
15+
* Called if InstanceID token is updated. This may occur if the security of
16+
* the previous token had been compromised. This call is initiated by the
17+
* InstanceID provider.
18+
*/
19+
// [START refresh_token]
20+
@Override
21+
public void onTokenRefresh() {
22+
// Fetch updated Instance ID token and notify our app's server of any changes (if applicable).
23+
Intent intent = new Intent(this, RegistrationIntentService.class);
24+
startService(intent);
25+
}
26+
// [END refresh_token]
27+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.example.instabug.gcm;
2+
3+
import android.app.IntentService;
4+
import android.content.Intent;
5+
import android.content.SharedPreferences;
6+
import android.preference.PreferenceManager;
7+
import android.support.v4.content.LocalBroadcastManager;
8+
import android.util.Log;
9+
import com.google.android.gms.gcm.GoogleCloudMessaging;
10+
import com.google.android.gms.iid.InstanceID;
11+
import com.instabug.library.Instabug;
12+
13+
14+
/**
15+
* Created by vezikon on 6/27/16.
16+
*/
17+
public class RegistrationIntentService extends IntentService {
18+
19+
20+
private static final String TAG = "RegIntentService";
21+
22+
public RegistrationIntentService() {
23+
super(TAG);
24+
}
25+
26+
@Override
27+
protected void onHandleIntent(Intent intent) {
28+
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
29+
30+
try {
31+
// [START register_for_gcm]
32+
// Initially this call goes out to the network to retrieve the token, subsequent calls
33+
// are local.
34+
// R.string.gcm_defaultSenderId (the Sender ID) is typically derived from google-services.json.
35+
// See https://developers.google.com/cloud-messaging/android/start for details on this file.
36+
// [START get_token]
37+
InstanceID instanceID = InstanceID.getInstance(this);
38+
String token = instanceID.getToken(QuickstartPreferences.SENDER_ID,
39+
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
40+
// [END get_token]
41+
Log.i(TAG, "GCM Registration Token: " + token);
42+
43+
// TODO: Implement this method to send any registration to your app's servers.
44+
sendRegistrationToServer(token);
45+
46+
// You should store a boolean that indicates whether the generated token has been
47+
// sent to your server. If the boolean is false, send the token to your server,
48+
// otherwise your server should have already received the token.
49+
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
50+
// [END register_for_gcm]
51+
} catch (Exception e) {
52+
Log.d(TAG, "Failed to complete token refresh", e);
53+
// If an exception happens while fetching the new token or updating our registration data
54+
// on a third-party server, this ensures that we'll attempt the update at a later time.
55+
sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
56+
}
57+
// Notify UI that registration has completed, so the progress indicator can be hidden.
58+
Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
59+
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
60+
}
61+
62+
/**
63+
* Persist registration to third-party servers.
64+
*
65+
* Modify this method to associate the user's GCM registration token with any server-side account
66+
* maintained by your application.
67+
*
68+
* @param token The new token.
69+
*/
70+
private void sendRegistrationToServer(String token) {
71+
// send your registration token to Instabug
72+
Instabug.setPushNotificationRegistrationToken(token);
73+
}
74+
75+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.widget.Toast;
1919

2020
import com.example.instabug.R;
21+
import com.example.instabug.gcm.RegistrationIntentService;
2122
import com.instabug.library.Instabug;
2223

2324
import butterknife.Bind;
@@ -39,6 +40,8 @@ protected void onCreate(Bundle savedInstanceState) {
3940
setContentView(R.layout.activity_main);
4041
ButterKnife.bind(this);
4142

43+
registerGCM();
44+
4245
headerImage = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.headerImageView);
4346
headerImage.setOnClickListener(new View.OnClickListener() {
4447
@Override
@@ -59,6 +62,13 @@ public void onClick(View v) {
5962
if (savedInstanceState == null) {
6063
navigationView.setCheckedItem(navigationView.getMenu().getItem(0).getItemId());
6164
}
65+
66+
}
67+
68+
private void registerGCM() {
69+
// Start IntentService to register this application with GCM.
70+
Intent intent = new Intent(this, RegistrationIntentService.class);
71+
startService(intent);
6272
}
6373

6474
@OnClick(R.id.feedback_fab)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.5.0'
8+
classpath 'com.android.tools.build:gradle:2.1.2'
99
}
1010
}
1111

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Oct 21 11:34:03 PDT 2015
1+
#Mon Jun 27 13:14:35 EET 2016
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

0 commit comments

Comments
 (0)