diff --git a/android/LICENSE b/android/LICENSE index 6ae867d..27f06a5 100644 --- a/android/LICENSE +++ b/android/LICENSE @@ -1 +1,21 @@ -TODO: place your license here and we'll include it in the module distribution +The MIT License (MIT) + +Copyright (c) 2015 Caffeina + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/android/dist/map.jar b/android/dist/map.jar deleted file mode 100644 index 55ad1fa..0000000 Binary files a/android/dist/map.jar and /dev/null differ diff --git a/android/dist/ti.goosh-android-1.5.0.zip b/android/dist/ti.goosh-android-1.6.0.zip similarity index 97% rename from android/dist/ti.goosh-android-1.5.0.zip rename to android/dist/ti.goosh-android-1.6.0.zip index 93a260f..05c1dd4 100644 Binary files a/android/dist/ti.goosh-android-1.5.0.zip and b/android/dist/ti.goosh-android-1.6.0.zip differ diff --git a/android/dist/ti.goosh.jar b/android/dist/ti.goosh.jar index 2c277bd..16b64bc 100644 Binary files a/android/dist/ti.goosh.jar and b/android/dist/ti.goosh.jar differ diff --git a/android/manifest b/android/manifest index 20912b7..c61ed46 100755 --- a/android/manifest +++ b/android/manifest @@ -2,7 +2,7 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 1.5.0 +version: 1.6.0 apiversion: 2 architectures: armeabi armeabi-v7a x86 description: ti.goosh diff --git a/android/src/ti/goosh/IntentService.java b/android/src/ti/goosh/IntentService.java index 51c6829..77eb2f9 100755 --- a/android/src/ti/goosh/IntentService.java +++ b/android/src/ti/goosh/IntentService.java @@ -10,6 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.lang.reflect.Type; import java.lang.Math; +import java.util.Random; import android.app.Notification; import android.app.NotificationManager; @@ -77,7 +78,7 @@ private Bitmap getBitmapFromURL(String src) throws Exception { } private void parseNotification(Bundle bundle) { - Context context = TiApplication.getInstance().getApplicationContext(); + Context context = getApplicationContext(); Boolean appInBackground = !TiApplication.isCurrentActivityInForeground(); Boolean showNotification = true; @@ -110,21 +111,11 @@ private void parseNotification(Bundle bundle) { if (showNotification) { + Intent notificationIntent = new Intent(this, PushHandlerActivity.class); + notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + notificationIntent.putExtra(TiGooshModule.INTENT_EXTRA, jsonData); - // If the Application has a current activity, relaunch it - // otherwise, we need a LaunchIntent - Intent launcherIntent = null; - if (TiApplication.getAppRootOrCurrentActivity() == null) { - launcherIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); - launcherIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_SINGLE_TOP); - launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); - } else { - launcherIntent = TiApplication.getAppRootOrCurrentActivity().getIntent(); - } - - launcherIntent.putExtra("tigoosh.notification", jsonData); - - PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launcherIntent, PendingIntent.FLAG_ONE_SHOT); + PendingIntent contentIntent = PendingIntent.getActivity(this, new Random().nextInt(), notificationIntent, PendingIntent.FLAG_ONE_SHOT); // Start building notification diff --git a/android/src/ti/goosh/PushHandlerActivity.java b/android/src/ti/goosh/PushHandlerActivity.java new file mode 100644 index 0000000..3b76150 --- /dev/null +++ b/android/src/ti/goosh/PushHandlerActivity.java @@ -0,0 +1,42 @@ +package ti.goosh; + +import android.app.Activity; +import android.app.NotificationManager; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.util.Log; + +import org.appcelerator.titanium.TiApplication; + +public class PushHandlerActivity extends Activity { + + private static String LCAT = "ti.goosh.TiGooshPushHandlerActivity"; + + @Override + public void onCreate(Bundle savedInstanceState) { + Log.d(LCAT, "started"); + super.onCreate(savedInstanceState); + + Context context = getApplicationContext(); + String notification = getIntent().getStringExtra(TiGooshModule.INTENT_EXTRA); + TiGooshModule instance = TiGooshModule.getInstance(); + + Intent launcherIntent; + + if (instance == null) { + launcherIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); + launcherIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); + } else { + launcherIntent = TiApplication.getAppRootOrCurrentActivity().getIntent(); + instance.sendMessage(notification, true); + } + + launcherIntent.putExtra(TiGooshModule.INTENT_EXTRA, notification); + startActivity(launcherIntent); + + finish(); + } + +} \ No newline at end of file diff --git a/android/src/ti/goosh/TiGooshActivityLifecycleCallbacks.java b/android/src/ti/goosh/TiGooshActivityLifecycleCallbacks.java deleted file mode 100644 index 7071c29..0000000 --- a/android/src/ti/goosh/TiGooshActivityLifecycleCallbacks.java +++ /dev/null @@ -1,38 +0,0 @@ -package ti.goosh; - -import android.app.Application.ActivityLifecycleCallbacks; -import org.appcelerator.titanium.TiApplication; -import org.appcelerator.titanium.TiRootActivity; -import android.app.Activity; -import android.os.Bundle; -import android.util.Log; - -final class TiGooshActivityLifecycleCallbacks implements ActivityLifecycleCallbacks { - - private static final String LCAT = "ti.goosh.TiGooshModule"; - - public void onActivityDestroyed(Activity activity) {} - public void onActivityPaused(Activity activity) {} - public void onActivityCreated(Activity activity, Bundle bundle) {} - public void onActivitySaveInstanceState(Activity activity, Bundle outState) {} - public void onActivityStopped(Activity activity) {} - - public void onActivityStarted(Activity activity) { - if (activity.getLocalClassName().equals("org.appcelerator.titanium.TiActivity") == false) return; - - TiGooshModule instance = TiGooshModule.getInstance(); - if (instance == null || instance.registered == false) return; - - instance.parseIncomingNotificationIntent(); - } - - public void onActivityResumed(Activity activity) { - if (activity.getLocalClassName().equals("org.appcelerator.titanium.TiActivity") == false) return; - - TiGooshModule instance = TiGooshModule.getInstance(); - if (instance == null || instance.registered == false) return; - - instance.parseIncomingNotificationIntent(); - } - -} \ No newline at end of file diff --git a/android/src/ti/goosh/TiGooshModule.java b/android/src/ti/goosh/TiGooshModule.java index 74a4f24..e806d19 100644 --- a/android/src/ti/goosh/TiGooshModule.java +++ b/android/src/ti/goosh/TiGooshModule.java @@ -46,6 +46,9 @@ public class TiGooshModule extends KrollModule { private static final String LCAT = "ti.goosh.TiGooshModule"; private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000; + public static final String INTENT_EXTRA = "tigoosh.notification"; + public static final String TOKEN = "tigoosh.token"; + private static TiGooshModule instance = null; private KrollFunction successCallback = null; @@ -63,22 +66,16 @@ public static TiGooshModule getInstance() { return instance; } - @Kroll.onAppCreate - public static void onAppCreate(TiApplication app) { - // Register the events to ensure the Intent parsing on resume - TiApplication.getInstance().registerActivityLifecycleCallbacks(new TiGooshActivityLifecycleCallbacks()); - Log.d(LCAT, "onAppCreate " + app + " (" + (instance != null) + ")"); - } - - public void parseIncomingNotificationIntent() { + public void parseBootIntent() { try { - Activity root = TiApplication.getAppRootOrCurrentActivity(); - Intent intent = root.getIntent(); + Intent intent = TiApplication.getAppRootOrCurrentActivity().getIntent(); - if (intent.hasExtra("tigoosh.notification")) { + if (intent.hasExtra(INTENT_EXTRA)) { - TiGooshModule.getInstance().sendMessage(intent.getStringExtra("tigoosh.notification"), true); - intent.removeExtra("tigoosh.notification"); + String notification = intent.getStringExtra(INTENT_EXTRA); + + intent.removeExtra(INTENT_EXTRA); + instance.sendMessage(notification, true); } else { Log.d(LCAT, "No notification in Intent"); @@ -122,7 +119,7 @@ public void registerForPushNotifications(HashMap options) { messageCallback = options.containsKey("callback") ? (KrollFunction)options.get("callback") : null; registered = true; - parseIncomingNotificationIntent(); + parseBootIntent(); if (checkPlayServices()) { activity.startService( new Intent(activity, RegistrationIntentService.class) ); @@ -167,13 +164,13 @@ public void cancel(int id) { @Kroll.method @Kroll.getProperty public Boolean isRemoteNotificationsEnabled() { - return getDefaultSharedPreferences().contains("tigoosh.token"); + return getDefaultSharedPreferences().contains(TOKEN); } @Kroll.method @Kroll.getProperty public String getRemoteDeviceUUID() { - return getDefaultSharedPreferences().getString("tigoosh.token", ""); + return getDefaultSharedPreferences().getString(TOKEN, ""); } @Kroll.method @@ -193,7 +190,7 @@ private SharedPreferences getDefaultSharedPreferences() { } private void saveToken(String token) { - getDefaultSharedPreferences().edit().putString("tigoosh.token", token).apply(); + getDefaultSharedPreferences().edit().putString(TOKEN, token).apply(); } // Public @@ -230,7 +227,7 @@ public void sendMessage(String data, Boolean inBackground) { } try { - + HashMap e = new HashMap(); e.put("data", data); // to parse on reverse on JS side e.put("inBackground", inBackground); diff --git a/android/timodule.xml b/android/timodule.xml index 865ece9..56c6971 100755 --- a/android/timodule.xml +++ b/android/timodule.xml @@ -16,7 +16,6 @@ - @@ -49,6 +48,11 @@ android:name="ti.goosh.RegistrationIntentService" android:exported="false"> + + +