Skip to content
This repository was archived by the owner on Jul 28, 2022. It is now read-only.

Commit 0c42f40

Browse files
authored
Upgrade to Batch SDK 1.12 + GCM -> FCM migration (#11)
* Take into account root project config * Upgrade Batch SDK * Remove GCM things * Add paragraph on small push notification icon * Remove unneeded permissions in AndroidManifest * Fix for older build tools
1 parent 48935d8 commit 0c42f40

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,40 @@ pod install
3434

3535
#### Android
3636

37-
Go to the Batch dashboard, create an Android app and setup your GCM configuration.
37+
Go to the Batch dashboard, create an Android app and setup your FCM configuration.
38+
Make sure to have added Firebase Messaging as stated in the [Batch documentation](https://batch.com/doc/android/sdk-integration.html#_adding-push-notifications-support).
3839
Then, in `android/app/build.gradle`, provide in your config:
3940

4041
```
4142
defaultConfig {
4243
...
43-
resValue "string", "GCM_SENDER_ID", "%YOUR_GCM_SENDER_ID%"
4444
resValue "string", "BATCH_API_KEY", "%YOUR_BATCH_API_KEY%"
4545
}
4646
```
4747

4848
Note that you can also customize the keys depending on your product flavor or build type.
4949

50+
#### Small push notification icon
51+
52+
It is recommended to provide a small notification icon in your `MainActivity.java`:
53+
54+
```java
55+
// push_icon.png in your res/drawable-{dpi} folder
56+
import com.batch.android.Batch;
57+
import android.os.Bundle;
58+
import android.graphics.Color;
59+
60+
...
61+
62+
@Override
63+
protected void onCreate(Bundle savedInstanceState) {
64+
super.onCreate(savedInstanceState);
65+
66+
Batch.Push.setSmallIconResourceId(R.drawable.push_icon);
67+
Batch.Push.setNotificationsColor(Color.parseColor(getResources().getString(R.color.pushIconBackground)));
68+
}
69+
```
70+
5071
##### Mobile landings and in-app messaging
5172

5273
If you set a custom `launchMode` in your `AndroidManifest.xml`, add in your `MainActivity.java`:

android/build.gradle

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
def DEFAULT_COMPILE_SDK_VERSION = 25
2+
def DEFAULT_BUILD_TOOLS_VERSION = "25.0.2"
3+
def DEFAULT_TARGET_SDK_VERSION = 22
4+
15
buildscript {
26
repositories {
37
jcenter()
@@ -11,12 +15,12 @@ buildscript {
1115
apply plugin: 'com.android.library'
1216

1317
android {
14-
compileSdkVersion 25
15-
buildToolsVersion "25.0.2"
18+
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
19+
buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
1620

1721
defaultConfig {
1822
minSdkVersion 16
19-
targetSdkVersion 22
23+
targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
2024
versionCode 1
2125
versionName "1.0"
2226
}
@@ -34,7 +38,5 @@ repositories {
3438

3539
dependencies {
3640
compile 'com.facebook.react:react-native:+'
37-
compile "com.batch.android:batch-sdk:1.10.2+"
38-
compile "com.google.android.gms:play-services-base:+"
39-
compile 'com.google.android.gms:play-services-gcm:+'
41+
compile "com.batch.android:batch-sdk:1.12.0+"
4042
}
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="tech.bam.RNBatchPush">
3-
4-
<uses-permission android:name="android.permission.INTERNET" />
5-
<uses-permission android:name="android.permission.WAKE_LOCK" />
6-
<uses-permission android:name="android.permission.VIBRATE" />
7-
<permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
8-
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
9-
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
10-
11-
<application>
12-
<service android:name="com.batch.android.BatchPushService" />
13-
<receiver android:name="com.batch.android.BatchPushReceiver" android:permission="com.google.android.c2dm.permission.SEND">
14-
<intent-filter>
15-
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
16-
<category android:name="${applicationId}" />
17-
</intent-filter>
18-
</receiver>
19-
20-
<service android:name="com.batch.android.BatchPushInstanceIDService" android:exported="true">
21-
<intent-filter>
22-
<action android:name="com.google.android.gms.iid.InstanceID"/>
23-
</intent-filter>
24-
</service>
25-
</application>
263
</manifest>

android/src/main/java/tech/bam/RNBatchPush/RNBatchPushModule.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public RNBatchPushModule(ReactApplicationContext reactContext) {
3838
Resources resources = reactContext.getResources();
3939
String packageName = reactContext.getApplicationContext().getPackageName();
4040
this.batchAPIKey = resources.getString(resources.getIdentifier("BATCH_API_KEY", "string", packageName));
41-
42-
Batch.Push.setGCMSenderId(resources.getString(resources.getIdentifier("GCM_SENDER_ID", "string", packageName)));
4341
Batch.setConfig(new Config(this.batchAPIKey));
4442

4543
startBatch();

0 commit comments

Comments
 (0)