Skip to content

Commit

Permalink
Merge pull request #32 from jvandijk/feature/upgrade-android-sdk
Browse files Browse the repository at this point in the history
Upgrade Android SDK to version 3.4.4
  • Loading branch information
williamrijksen authored Apr 26, 2017
2 parents 4dadf0b + 0c1cb11 commit 5a751bc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ before_install:

install:
- cd $MODULE_ROOT
- curl -o install.sh https://raw.githubusercontent.com/williamrijksen/ci/v8/travis/install.sh
- source install.sh -s "--branch master"
- curl -o install.sh https://rawcdn.githack.com/williamrijksen/ci/v8/travis/install.sh
- source install.sh -s "--branch 6_0_X"

before_script:
- curl -o script.sh https://raw.githubusercontent.com/williamrijksen/ci/v8/travis/script.sh
- curl -o script.sh https://rawcdn.githack.com/williamrijksen/ci/v8/travis/script.sh
- chmod +x script.sh

script:
Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ This module gives you the possibility to integrate OneSignal into you're Appcele

Before setting up the Titanium SDK, you must generate the appropriate credentials for the platform(s) you are releasing on:

- iOS - [Generate an iOS Push Certificate](https://documentation.onesignal.com/docs/generate-an-ios-push-certificate)
- iOS - [Generate an iOS Push Certificate](https://documentation.onesignal.com/docs/generate-an-ios-push-certificate)
- ANDROID - [Generate a Google Server API Key](https://documentation.onesignal.com/docs/generate-a-google-server-api-key)

## Follow Guide

### Setup

1. Integrate the module into the `modules` folder and define them into the `tiapp.xml` file:

```xml
<modules>
<module platform="iphone" version="1.5.1">com.williamrijksen.onesignal</module>
<module platform="android" version="1.5.1">com.williamrijksen.onesignal</module>
<module platform="android" version="1.6.0">com.williamrijksen.onesignal</module>
</modules>
```
1. Configure your app into the App Settings panel for the right Platform (Android and/or iOS).
1. To use OneSignal on iOS devices, register the OneSignal-appId into `tiapp.xml`:

```xml
<property name="OneSignal_AppID" type="string">[App-id]</property>
```
1. To use OneSignal on Android devices, register some meta-data as well:
```
1. To use OneSignal on Android devices, register some meta-data as well:

```xml
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Expand All @@ -40,18 +40,18 @@ Before setting up the Titanium SDK, you must generate the appropriate credential

### Usage
1. Register device for Push Notifications

```js
// This registers your device automatically into OneSignal
var onesignal = require('com.williamrijksen.onesignal');
```
1. To add the possibility to target people for notifications, send a tag:

```js
onesignal.sendTag({ key: 'foo', value: 'bar' });
```
1. Delete tag:

```js
onesignal.deleteTag({ key: 'foo' });
```
Expand All @@ -63,18 +63,18 @@ Before setting up the Titanium SDK, you must generate the appropriate credential
Ti.API.error("Error: " + e.error);
return
}

Ti.API.info(Ti.Platform.osname === "iphone"? e.results : JSON.parse(e.results));
});
```
1. IdsAvailable (iOS-only for now):
```
1. IdsAvailable:

```js
onesignal.idsAvailable(function(e) {
//pushToken will be nil if the user did not accept push notifications
alert(e);
});
```
```
1. postNotification (iOS-only for now):

```js
Expand All @@ -83,15 +83,15 @@ Before setting up the Titanium SDK, you must generate the appropriate credential
message:'Titanium test message',
playerIds:["00000000-0000-0000-0000-000000000000"]
});
```
```
1. Set log level (iOS-only for now):

```js
onesignal.setLogLevel({
logLevel: onesignal.LOG_LEVEL_DEBUG,
visualLevel: onesignal.LOG_LEVEL_NONE
});
```
```
1. Receive notifications callback: (does not work on iOS when the app is closed (swiped away). But works fine when the app is running on background)
Opened:

Expand Down
Binary file modified android/lib/OneSignalSDK.jar
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.5.1
version: 1.6.0
apiversion: 3
architectures: armeabi-v7a x86
description: com.williamrijksen.onesignal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.williamrijksen.onesignal;

import android.content.Context;
import android.app.Activity;

import com.onesignal.OneSignal;
import com.onesignal.OSNotification;
Expand All @@ -23,29 +23,50 @@ public class ComWilliamrijksenOnesignalModule extends KrollModule
{
private static final String LCAT = "ComWilliamrijksenOnesignalModule";
private static final boolean DBG = TiConfig.LOGD;
private boolean oneSignalInitDone;

public ComWilliamrijksenOnesignalModule()
{
super();
TiApplication appContext = TiApplication.getInstance();
initOneSignal(TiApplication.getInstance().getCurrentActivity());
}

private void initOneSignal(Activity activity)
{
if (activity == null || oneSignalInitDone) {
return;
}

oneSignalInitDone = true;

OneSignal
.startInit(appContext)
.setNotificationReceivedHandler(new NotificationReceivedHandler())
.setNotificationOpenedHandler(new NotificationOpenedHandler())
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.None)
.init();
.startInit(activity)
.setNotificationReceivedHandler(new NotificationReceivedHandler())
.setNotificationOpenedHandler(new NotificationOpenedHandler())
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.None)
.init();
}
//TODO inFocusDisplaying should be configurable from Titanium App module initialization

//variable to store the received call back function for the getTags method call
private KrollFunction getTagsCallback = null;

private KrollFunction idsAvailableCallback = null;

@Kroll.onAppCreate
public static void onAppCreate(TiApplication app)
{
Log.d(LCAT, "inside onAppCreate");
}

@Override
public void onResume(Activity activity)
{
super.onResume(activity);
Log.d(LCAT, "Trying to initialize OneSignal if necessary");
initOneSignal(activity);
}

@Kroll.method
public void sendTag(Object tag)
{
Expand All @@ -70,6 +91,13 @@ public void getTags(KrollFunction handler)
OneSignal.getTags(new GetTagsHandler());
}

@Kroll.method
public void idsAvailable(KrollFunction handler)
{
idsAvailableCallback = handler;
OneSignal.idsAvailable(new IdsAvailableHandler());
}

private class GetTagsHandler implements OneSignal.GetTagsHandler {
@Override
public void tagsAvailable(JSONObject tags) {
Expand All @@ -89,6 +117,22 @@ public void tagsAvailable(JSONObject tags) {
}
}

private class IdsAvailableHandler implements OneSignal.IdsAvailableHandler {
@Override
public void idsAvailable(String userId, String registrationId)
{
HashMap<String, Object> dict = new HashMap<String, Object>();
try {
dict.put("userId", userId);
dict.put("pushToken", registrationId);
} catch (Exception e) {
Log.d("error:", e.toString());
}

idsAvailableCallback.call(getKrollObject(), dict);
}
}

private class NotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
// This fires when a notification is opened by tapping on it.
@Override
Expand Down

0 comments on commit 5a751bc

Please sign in to comment.