Commit bac11ebc authored by d4vidi's avatar d4vidi

Add various fixes

parent a34a79d9
...@@ -76,8 +76,8 @@ And the following methods to support registration and receiving notifications: ...@@ -76,8 +76,8 @@ And the following methods to support registration and receiving notifications:
Add a reference to the library's native code in your global `settings.gradle`: Add a reference to the library's native code in your global `settings.gradle`:
``` ```
include ':reactnativenotifications' include ':react-native-notifications'
project(':reactnativenotifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/android') project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/android')
``` ```
Declare the library as a dependency in your **app-project's** `build.gradle`: Declare the library as a dependency in your **app-project's** `build.gradle`:
...@@ -85,7 +85,8 @@ Declare the library as a dependency in your **app-project's** `build.gradle`: ...@@ -85,7 +85,8 @@ Declare the library as a dependency in your **app-project's** `build.gradle`:
``` ```
dependencies { dependencies {
// ... // ...
compile project(':reactnativenotifications')
compile project(':react-native-notifications')
} }
``` ```
...@@ -95,13 +96,13 @@ dependencies { ...@@ -95,13 +96,13 @@ dependencies {
Push notifications on Android are managed and dispatched using [Google's GCM service](https://developers.google.com/cloud-messaging/gcm) (now integrated into Firebase). The following installation steps are a TL;DR of [Google's GCM setup guide](https://developers.google.com/cloud-messaging/android/client). You can follow them to get GCM integrated quickly, but we recommend that you will in the very least have a peek at the guide's overview. Push notifications on Android are managed and dispatched using [Google's GCM service](https://developers.google.com/cloud-messaging/gcm) (now integrated into Firebase). The following installation steps are a TL;DR of [Google's GCM setup guide](https://developers.google.com/cloud-messaging/android/client). You can follow them to get GCM integrated quickly, but we recommend that you will in the very least have a peek at the guide's overview.
##### Step #1: Subscribe to Google's GCM #### Step #1: Subscribe to Google's GCM
To set GCM in your app, you must first create a Google API-project and obtain a **Sender ID** and a **Server API Key**. If you have no existing API project yet, the easiest way to go about in creating one is using [this step-by-step installation process](https://developers.google.com/mobile/add); Use [this tutorial](https://code.tutsplus.com/tutorials/how-to-get-started-with-push-notifications-on-android--cms-25870) for insturctions. To set GCM in your app, you must first create a Google API-project and obtain a **Sender ID** and a **Server API Key**. If you have no existing API project yet, the easiest way to go about in creating one is using [this step-by-step installation process](https://developers.google.com/mobile/add); Use [this tutorial](https://code.tutsplus.com/tutorials/how-to-get-started-with-push-notifications-on-android--cms-25870) for insturctions.
Alternatively, follow [Google's complete guide](https://developers.google.com/cloud-messaging/android/client#create-an-api-project). Alternatively, follow [Google's complete guide](https://developers.google.com/cloud-messaging/android/client#create-an-api-project).
##### Step #2: Add Sender ID to Manifest File #### Step #2: Add Sender ID to Manifest File
Once obtained, bundle the Sender ID onto your main `manifest.xml` file: Once obtained, bundle the Sender ID onto your main `manifest.xml` file:
...@@ -118,6 +119,15 @@ Once obtained, bundle the Sender ID onto your main `manifest.xml` file: ...@@ -118,6 +119,15 @@ Once obtained, bundle the Sender ID onto your main `manifest.xml` file:
``` ```
#### Step #3: Add / verify GCM dependency in `build.gradle`:
```
dependencies {
// If you haven't already done so, add Google's GCM module:
compile "com.google.android.gms:play-services-gcm:9+"
}
```
--- ---
......
...@@ -20,7 +20,7 @@ android { ...@@ -20,7 +20,7 @@ android {
dependencies { dependencies {
// Google's GCM related framework components. // Google's GCM related framework components.
compile "com.google.android.gms:play-services-gcm:9+" compile "com.google.android.gms:play-services-gcm:9.4.0"
compile 'com.facebook.react:react-native:+' compile 'com.facebook.react:react-native:+'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
......
...@@ -44,7 +44,7 @@ public class PushNotification implements IPushNotification { ...@@ -44,7 +44,7 @@ public class PushNotification implements IPushNotification {
protected PushNotification(Context context, Bundle bundle, AppLifecycleFacade appLifecycleFacade) { protected PushNotification(Context context, Bundle bundle, AppLifecycleFacade appLifecycleFacade) {
mContext = context; mContext = context;
mAppLifecycleFacade = appLifecycleFacade; mAppLifecycleFacade = appLifecycleFacade;
mNotificationProps = new PushNotificationProps(bundle); mNotificationProps = createProps(bundle);
} }
public static IPushNotification get(Context context, Bundle bundle, AppLifecycleFacade facade) { public static IPushNotification get(Context context, Bundle bundle, AppLifecycleFacade facade) {
...@@ -97,6 +97,10 @@ public class PushNotification implements IPushNotification { ...@@ -97,6 +97,10 @@ public class PushNotification implements IPushNotification {
} }
} }
protected PushNotificationProps createProps(Bundle bundle) {
return new PushNotificationProps(bundle);
}
protected void setAsInitialNotification() { protected void setAsInitialNotification() {
InitialNotification.set(mNotificationProps); InitialNotification.set(mNotificationProps);
} }
......
...@@ -2,20 +2,21 @@ package com.wix.reactnativenotifications.core.notification; ...@@ -2,20 +2,21 @@ package com.wix.reactnativenotifications.core.notification;
import android.os.Bundle; import android.os.Bundle;
/**
* @author amitd
*/
public class PushNotificationProps { public class PushNotificationProps {
private Bundle mBundle; protected Bundle mBundle;
public PushNotificationProps(Bundle bundle) { public PushNotificationProps() {
final String title = bundle.getString("title"); mBundle = new Bundle();
final String body = bundle.getString("body"); }
if (title == null || title.trim().isEmpty() || body == null || body.trim().isEmpty()) {
throw new IllegalArgumentException("Invalid notification"); public PushNotificationProps(String title, String body) {
mBundle = new Bundle();
mBundle.putString("title", title);
mBundle.putString("body", body);
} }
public PushNotificationProps(Bundle bundle) {
mBundle = bundle; mBundle = bundle;
} }
......
package com.wix.reactnativenotifications.core.notificationdrawer; package com.wix.reactnativenotifications.core.notificationdrawer;
import android.content.Context;
public interface INotificationsDrawerApplication { public interface INotificationsDrawerApplication {
IPushNotificationsDrawer getPushNotificationsDrawer(); IPushNotificationsDrawer getPushNotificationsDrawer(Context context);
} }
...@@ -18,7 +18,7 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer { ...@@ -18,7 +18,7 @@ public class PushNotificationsDrawer implements IPushNotificationsDrawer {
public static IPushNotificationsDrawer get(Context context) { public static IPushNotificationsDrawer get(Context context) {
final Context appContext = context.getApplicationContext(); final Context appContext = context.getApplicationContext();
if (appContext instanceof INotificationsDrawerApplication) { if (appContext instanceof INotificationsDrawerApplication) {
return ((INotificationsDrawerApplication) appContext).getPushNotificationsDrawer(); return ((INotificationsDrawerApplication) appContext).getPushNotificationsDrawer(context);
} }
return new PushNotificationsDrawer(context); return new PushNotificationsDrawer(context);
......
...@@ -32,7 +32,8 @@ dependencies { ...@@ -32,7 +32,8 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0' compile 'com.android.support:design:23.4.0'
compile 'com.facebook.react:react-native:+' compile 'com.facebook.react:react-native:+'
compile project(':reactnativenotifications') compile "com.google.android.gms:play-services-gcm:9+"
compile project(':react-native-notifications')
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }
include ':myapplication' include ':myapplication'
include ':reactnativenotifications' include ':react-native-notifications'
project(':reactnativenotifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/android') project(':react-native-notifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-notifications/android')
...@@ -41,6 +41,10 @@ export class NotificationsAndroid { ...@@ -41,6 +41,10 @@ export class NotificationsAndroid {
notificationReceivedListener = null; notificationReceivedListener = null;
} }
} }
static refreshToken() {
RNNotifications.refreshToken();
}
} }
export class PendingNotifications { export class PendingNotifications {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment