Skip to content

Commit fbf105a

Browse files
committed
Updated Android Studio example to SDK 2.0
1 parent ce5ad7d commit fbf105a

File tree

6 files changed

+95
-114
lines changed

6 files changed

+95
-114
lines changed

Examples/AndroidStudio/app/app.iml

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,47 +65,42 @@
6565
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
6767
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
68-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
68+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
6969
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
70-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
7170
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
72-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
73-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
74-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/jars" />
75-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.0/jars" />
76-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/8.1.0/jars" />
77-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/8.1.0/jars" />
78-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/8.1.0/jars" />
79-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/8.1.0/jars" />
80-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.1.0/jars" />
81-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-gcm/8.1.0/jars" />
82-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.onesignal/OneSignal/1.10.7/jars" />
71+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
72+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
73+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-analytics/8.3.0/jars" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/8.3.0/jars" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.3.0/jars" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-gcm/8.3.0/jars" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-location/8.3.0/jars" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-maps/8.3.0/jars" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-measurement/8.3.0/jars" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.onesignal/OneSignal/2.0.0/jars" />
8381
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
84-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
85-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
86-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
87-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
8883
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
89-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
9084
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
91-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
9285
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
9386
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
9487
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
88+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
9589
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
9690
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
9791
</content>
9892
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
9993
<orderEntry type="sourceFolder" forTests="false" />
100-
<orderEntry type="library" exported="" name="play-services-analytics-8.1.0" level="project" />
101-
<orderEntry type="library" exported="" name="play-services-base-8.1.0" level="project" />
102-
<orderEntry type="library" exported="" name="OneSignal-1.10.7" level="project" />
103-
<orderEntry type="library" exported="" name="support-annotations-23.1.0" level="project" />
104-
<orderEntry type="library" exported="" name="play-services-ads-8.1.0" level="project" />
105-
<orderEntry type="library" exported="" name="appcompat-v7-23.1.0" level="project" />
106-
<orderEntry type="library" exported="" name="play-services-appindexing-8.1.0" level="project" />
107-
<orderEntry type="library" exported="" name="play-services-basement-8.1.0" level="project" />
108-
<orderEntry type="library" exported="" name="play-services-gcm-8.1.0" level="project" />
109-
<orderEntry type="library" exported="" name="support-v4-23.1.0" level="project" />
94+
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
95+
<orderEntry type="library" exported="" name="play-services-location-8.3.0" level="project" />
96+
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
97+
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
98+
<orderEntry type="library" exported="" name="play-services-base-8.3.0" level="project" />
99+
<orderEntry type="library" exported="" name="OneSignal-2.0.0" level="project" />
100+
<orderEntry type="library" exported="" name="play-services-gcm-8.3.0" level="project" />
101+
<orderEntry type="library" exported="" name="play-services-analytics-8.3.0" level="project" />
102+
<orderEntry type="library" exported="" name="play-services-maps-8.3.0" level="project" />
103+
<orderEntry type="library" exported="" name="play-services-measurement-8.3.0" level="project" />
104+
<orderEntry type="library" exported="" name="play-services-basement-8.3.0" level="project" />
110105
</component>
111106
</module>

Examples/AndroidStudio/app/build.gradle

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 23
5-
buildToolsVersion "23.0.1"
5+
buildToolsVersion "23.0.2"
66

77
defaultConfig {
88
applicationId "com.onesignal.example"
9-
// Required for OneSignal
10-
manifestPlaceholders = [manifestApplicationId:"${applicationId}"]
9+
10+
// TODO: Please update the Google Project number and OneSignal Id below to yours.
11+
manifestPlaceholders = [manifestApplicationId: "${applicationId}",
12+
onesignal_app_id: "b2f7f966-d8cc-11e4-bed1-df8f05be55ba",
13+
onesignal_google_project_number: "703322744261"]
1114

1215
minSdkVersion 10
1316
targetSdkVersion 23
@@ -25,10 +28,12 @@ android {
2528
dependencies {
2629
compile fileTree(dir: 'libs', include: ['*.jar'])
2730
testCompile 'junit:junit:4.12'
28-
compile 'com.android.support:appcompat-v7:23.1.0'
31+
compile 'com.android.support:appcompat-v7:+'
2932

30-
// OneSignal
31-
compile 'com.onesignal:OneSignal:1.+@aar'
32-
compile 'com.google.android.gms:play-services-gcm:8.1.0'
33-
compile 'com.google.android.gms:play-services-analytics:8.1.0'
33+
// OneSignal and required libraries
34+
compile 'com.onesignal:OneSignal:2.+@aar'
35+
compile 'com.google.android.gms:play-services-gcm:+'
36+
compile 'com.google.android.gms:play-services-analytics:+'
37+
compile "com.google.android.gms:play-services-location:+"
38+
compile 'com.android.support:appcompat-v7:23.1.1'
3439
}

Examples/AndroidStudio/app/src/androidTest/java/com/onesignal/example/ApplicationTest.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

Examples/AndroidStudio/app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
<!-- All OneSignal manifest entries are added for you automatically from the OneSignal aar gradle entry. -->
66

77
<application
8-
android:allowBackup="true"
98
android:icon="@drawable/ic_launcher"
109
android:label="@string/app_name"
11-
android:supportsRtl="true"
12-
android:theme="@style/AppTheme" >
13-
<activity android:name=".MainActivity" >
10+
android:theme="@style/AppTheme"
11+
android:name=".ExampleApplication">
12+
13+
<activity android:name=".MainActivity">
1414
<intent-filter>
1515
<action android:name="android.intent.action.MAIN" />
16-
1716
<category android:name="android.intent.category.LAUNCHER" />
1817
</intent-filter>
1918
</activity>
19+
2020
</application>
2121

2222
</manifest>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.onesignal.example;
2+
3+
import android.app.Application;
4+
import android.util.Log;
5+
6+
import com.onesignal.OneSignal;
7+
8+
import org.json.JSONObject;
9+
10+
public class ExampleApplication extends Application {
11+
12+
@Override
13+
public void onCreate() {
14+
super.onCreate();
15+
16+
// Logging set to help debug issues, remove before releasing your app.
17+
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.DEBUG, OneSignal.LOG_LEVEL.WARN);
18+
19+
OneSignal.startInit(this)
20+
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
21+
.init();
22+
}
23+
24+
25+
private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
26+
/**
27+
* Callback to implement in your app to handle when a notification is opened from the Android status bar or
28+
* a new one comes in while the app is running.
29+
* This method is located in this Application class as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
30+
*
31+
* @param message The message string the user seen/should see in the Android status bar.
32+
* @param additionalData The additionalData key value pair section you entered in on onesignal.com.
33+
* @param isActive Was the app in the foreground when the notification was received.
34+
*/
35+
@Override
36+
public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
37+
String additionalMessage = "";
38+
39+
try {
40+
if (additionalData != null) {
41+
if (additionalData.has("actionSelected"))
42+
additionalMessage += "Pressed ButtonID: " + additionalData.getString("actionSelected");
43+
44+
additionalMessage = message + "\nFull additionalData:\n" + additionalData.toString();
45+
}
46+
47+
Log.d("OneSignalExample", "message:\n" + message + "\nadditionalMessage:\n" + additionalMessage);
48+
} catch (Throwable t) {
49+
t.printStackTrace();
50+
}
51+
}
52+
}
53+
}
Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package com.onesignal.example;
22

33
import android.app.Activity;
4-
import android.support.v7.app.AlertDialog;
54
import android.support.v7.app.AppCompatActivity;
65
import android.os.Bundle;
76
import android.widget.TextView;
87

98
import com.onesignal.OneSignal;
10-
import com.onesignal.OneSignal.NotificationOpenedHandler;
11-
12-
import org.json.JSONException;
13-
import org.json.JSONObject;
149

1510
public class MainActivity extends AppCompatActivity {
1611

@@ -21,12 +16,6 @@ protected void onCreate(Bundle savedInstanceState) {
2116
super.onCreate(savedInstanceState);
2217
setContentView(R.layout.activity_main);
2318

24-
currentActivity = this;
25-
26-
// NOTE: Please update your Google Project number and OneSignal id to yours below.
27-
// Pass in your app's Context, Google Project number, your OneSignal App ID, and NotificationOpenedHandler
28-
OneSignal.init(this, "703322744261", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", new ExampleNotificationOpenedHandler());
29-
3019
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
3120
@Override
3221
public void idsAvailable(String userId, String registrationId) {
@@ -42,52 +31,4 @@ public void idsAvailable(String userId, String registrationId) {
4231
}
4332
});
4433
}
45-
46-
// NotificationOpenedHandler is implemented in its own class instead of adding implements to MainActivity so we don't hold on to a reference of our first activity if it gets recreated.
47-
private class ExampleNotificationOpenedHandler implements NotificationOpenedHandler {
48-
/**
49-
* Callback to implement in your app to handle when a notification is opened from the Android status bar or
50-
* a new one comes in while the app is running.
51-
* This method is located in this activity as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
52-
*
53-
* @param message The message string the user seen/should see in the Android status bar.
54-
* @param additionalData The additionalData key value pair section you entered in on onesignal.com.
55-
* @param isActive Was the app in the foreground when the notification was received.
56-
*/
57-
@Override
58-
public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
59-
String messageTitle = "OneSignal Example", messageBody = message;
60-
61-
try {
62-
if (additionalData != null) {
63-
if (additionalData.has("title"))
64-
messageTitle = additionalData.getString("title");
65-
if (additionalData.has("actionSelected"))
66-
messageBody += "\nPressed ButtonID: " + additionalData.getString("actionSelected");
67-
68-
messageBody = message + "\n\nFull additionalData:\n" + additionalData.toString();
69-
}
70-
} catch (JSONException e) {
71-
}
72-
73-
new AlertDialog.Builder(MainActivity.currentActivity)
74-
.setTitle(messageTitle)
75-
.setMessage(messageBody)
76-
.setCancelable(true)
77-
.setPositiveButton("OK", null)
78-
.create().show();
79-
}
80-
}
81-
82-
@Override
83-
protected void onPause() {
84-
super.onPause();
85-
OneSignal.onPaused();
86-
}
87-
@Override
88-
protected void onResume() {
89-
super.onResume();
90-
OneSignal.onResumed();
91-
}
92-
9334
}

0 commit comments

Comments
 (0)