Skip to content

Commit 29ab66b

Browse files
committed
Adding initial Android implementation.
1 parent e5fb04d commit 29ab66b

14 files changed

+759
-1
lines changed

android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android/app/build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apply plugin: 'com.android.library'
2+
3+
4+
android {
5+
compileSdkVersion 23
6+
buildToolsVersion "23.0.1"
7+
8+
defaultConfig {
9+
minSdkVersion 16
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
ndk {
14+
abiFilters "armeabi-v7a", "x86"
15+
}
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
dependencies {
25+
compile 'com.facebook.react:react-native:0.20.+'
26+
compile 'com.microsoft.azure:notification-hubs-android-sdk:0.4@aar'
27+
compile 'com.microsoft.azure:azure-notifications-handler:1.0.1@aar'
28+
}
29+
30+
repositories {
31+
maven {
32+
url "http://dl.bintray.com/microsoftazuremobile/SDK"
33+
}
34+
}

android/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.1"
6+
7+
defaultConfig {
8+
minSdkVersion 16
9+
targetSdkVersion 23
10+
versionCode 1
11+
versionName "1.0"
12+
ndk {
13+
abiFilters "armeabi-v7a", "x86"
14+
}
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
}
23+
24+
dependencies {
25+
compile fileTree(dir: 'libs', include: ['*.jar'])
26+
compile 'com.facebook.react:react-native:+'
27+
compile 'com.google.android.gms:play-services-gcm:9.4.0'
28+
compile 'com.google.firebase:firebase-messaging:9.4.0'
29+
compile 'com.microsoft.azure:notification-hubs-android-sdk:0.4@aar'
30+
compile 'com.microsoft.azure:azure-notifications-handler:1.0.1@aar'
31+
}
32+
33+
repositories {
34+
maven {
35+
url "http://dl.bintray.com/microsoftazuremobile/SDK"
36+
}
37+
}
38+

android/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/Cellar/android-sdk/24.4.1/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id=":react-native-azurenotificationhub" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/../../../android" external.system.id="GRADLE" external.system.module.group="myapp" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":react-native-azurenotificationhub" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
13+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
14+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
15+
<afterSyncTasks>
16+
<task>generateDebugSources</task>
17+
</afterSyncTasks>
18+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
19+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
20+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
21+
<option name="RES_FOLDERS_RELATIVE_PATH" value="" />
22+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
23+
<option name="LIBRARY_PROJECT" value="true" />
24+
</configuration>
25+
</facet>
26+
</component>
27+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
28+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
29+
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
30+
<exclude-output />
31+
<content url="file://$MODULE_DIR$">
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
41+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
42+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
43+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
44+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
45+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
62+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
63+
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
64+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
65+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
66+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
67+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
68+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
69+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
70+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
71+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
85+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
86+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
87+
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
89+
</content>
90+
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
91+
<orderEntry type="sourceFolder" forTests="false" />
92+
<orderEntry type="library" exported="" name="okio-1.9.0" level="project" />
93+
<orderEntry type="library" exported="" name="play-services-base-9.4.0" level="project" />
94+
<orderEntry type="library" exported="" name="fresco-0.11.0" level="project" />
95+
<orderEntry type="library" exported="" name="drawee-0.11.0" level="project" />
96+
<orderEntry type="library" exported="" name="jsr305-3.0.0" level="project" />
97+
<orderEntry type="library" exported="" name="bolts-tasks-1.4.0" level="project" />
98+
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
99+
<orderEntry type="library" exported="" name="okhttp-urlconnection-3.4.1" level="project" />
100+
<orderEntry type="library" exported="" name="android-jsc-r174650" level="project" />
101+
<orderEntry type="library" exported="" name="support-v4-23.2.1" level="project" />
102+
<orderEntry type="library" exported="" name="firebase-common-9.4.0" level="project" />
103+
<orderEntry type="library" exported="" name="firebase-iid-9.4.0" level="project" />
104+
<orderEntry type="library" exported="" name="support-annotations-23.2.1" level="project" />
105+
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
106+
<orderEntry type="library" exported="" name="fbcore-0.11.0" level="project" />
107+
<orderEntry type="library" exported="" name="imagepipeline-0.11.0" level="project" />
108+
<orderEntry type="library" exported="" name="play-services-gcm-9.4.0" level="project" />
109+
<orderEntry type="library" exported="" name="firebase-messaging-9.4.0" level="project" />
110+
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
111+
<orderEntry type="library" exported="" name="imagepipeline-base-0.11.0" level="project" />
112+
<orderEntry type="library" exported="" name="play-services-iid-9.4.0" level="project" />
113+
<orderEntry type="library" exported="" name="react-native-0.34.0-rc.0" level="project" />
114+
<orderEntry type="library" exported="" name="soloader-0.1.0" level="project" />
115+
<orderEntry type="library" exported="" name="play-services-basement-9.4.0" level="project" />
116+
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
117+
<orderEntry type="library" exported="" name="jackson-core-2.2.3" level="project" />
118+
<orderEntry type="library" exported="" name="play-services-tasks-9.4.0" level="project" />
119+
<orderEntry type="library" exported="" name="notification-hubs-android-sdk-0.4" level="project" />
120+
<orderEntry type="library" exported="" name="okhttp-ws-3.4.1" level="project" />
121+
<orderEntry type="library" exported="" name="okhttp-3.4.1" level="project" />
122+
<orderEntry type="library" exported="" name="imagepipeline-okhttp3-0.11.0" level="project" />
123+
<orderEntry type="library" exported="" name="azure-notifications-handler-1.0.1" level="project" />
124+
</component>
125+
</module>

android/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.azure.reactnative.notificationhub">
3+
4+
</manifest>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.azure.reactnative.notificationhub;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
import android.content.SharedPreferences.Editor;
6+
7+
public class NotificationHubUtil {
8+
private static NotificationHubUtil sharedNotificationHubUtilInstance = null;
9+
10+
private static final String SHARED_PREFS_NAME =
11+
"com.azure.reactnative.notificationhub.NotificationHubUtil";
12+
private static final String KEY_FOR_PREFS_REGISTRATIONID =
13+
"AzureNotificationHub_registrationID";
14+
private static final String KEY_FOR_PREFS_CONNECTIONSTRING =
15+
"AzureNotificationHub_connectionString";
16+
private static final String KEY_FOR_PREFS_HUBNAME =
17+
"AzureNotificationHub_hubName";
18+
private static final String KEY_FOR_PREFS_FCMTOKEN =
19+
"AzureNotificationHub_FCMToken";
20+
21+
22+
public static NotificationHubUtil getInstance() {
23+
if(sharedNotificationHubUtilInstance == null) {
24+
sharedNotificationHubUtilInstance = new NotificationHubUtil();
25+
}
26+
return sharedNotificationHubUtilInstance;
27+
}
28+
29+
public String getConnectionString(Context context) {
30+
return getPref(context, KEY_FOR_PREFS_CONNECTIONSTRING, null);
31+
}
32+
33+
public void setConnectionString(Context context, String connectionString) {
34+
setPref(context, KEY_FOR_PREFS_CONNECTIONSTRING, connectionString);
35+
}
36+
37+
public String getHubName(Context context) {
38+
return getPref(context, KEY_FOR_PREFS_HUBNAME, null);
39+
}
40+
41+
public void setHubName(Context context, String hubName) {
42+
setPref(context, KEY_FOR_PREFS_HUBNAME, hubName);
43+
}
44+
45+
public String getRegistrationID(Context context) {
46+
return getPref(context, KEY_FOR_PREFS_REGISTRATIONID, null);
47+
}
48+
49+
public void setRegistrationID(Context context, String registrationID) {
50+
setPref(context, KEY_FOR_PREFS_REGISTRATIONID, registrationID);
51+
}
52+
53+
public String getFCMToken(Context context) {
54+
return getPref(context, KEY_FOR_PREFS_FCMTOKEN, null);
55+
}
56+
57+
public void setFCMToken(Context context, String token) {
58+
setPref(context, KEY_FOR_PREFS_FCMTOKEN, token);
59+
}
60+
61+
private String getPref(Context context, String key, String defaultValue) {
62+
SharedPreferences prefs =
63+
context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
64+
return prefs.getString(key, defaultValue);
65+
}
66+
67+
private void setPref(Context context, String key, String value) {
68+
SharedPreferences.Editor editor =
69+
context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE).edit();
70+
editor.putString(key, value);
71+
editor.apply();
72+
}
73+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.azure.reactnative.notificationhub;
2+
3+
import android.content.Intent;
4+
import android.util.Log;
5+
import com.google.firebase.iid.FirebaseInstanceIdService;
6+
7+
public class ReactNativeInstanceIDService extends FirebaseInstanceIdService {
8+
9+
private static final String TAG = "MyInstanceIDService";
10+
11+
@Override
12+
public void onTokenRefresh() {
13+
14+
Log.i(TAG, "Refreshing GCM Registration Token");
15+
16+
Intent intent = new Intent(this, ReactNativeRegistrationIntentService.class);
17+
startService(intent);
18+
}
19+
};

0 commit comments

Comments
 (0)