diff --git a/app/build.gradle b/app/build.gradle index 83a2480..6f67128 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId 'com.samebits.beacon.locator' minSdkVersion 18 targetSdkVersion 22 - versionCode 110 - versionName '1.1.0' + versionCode 111 + versionName '1.1.1' testApplicationId 'com.samebits.beacon.locator.test' } buildTypes { @@ -58,7 +58,7 @@ dependencies { compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION" - compile 'org.altbeacon:android-beacon-library:2.9.1' + compile 'org.altbeacon:android-beacon-library:2.9.2' compile "com.google.dagger:dagger:$DAGGER_VERSION" apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION" provided 'org.glassfish:javax.annotation:10.0-b28' diff --git a/app/src/main/java/com/samebits/beacon/locator/action/StartAppAction.java b/app/src/main/java/com/samebits/beacon/locator/action/StartAppAction.java index 232f481..32ea483 100644 --- a/app/src/main/java/com/samebits/beacon/locator/action/StartAppAction.java +++ b/app/src/main/java/com/samebits/beacon/locator/action/StartAppAction.java @@ -20,10 +20,14 @@ import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import com.samebits.beacon.locator.R; import com.samebits.beacon.locator.model.NotificationAction; +import java.util.List; + /** * Created by vitas on 03/01/16. */ @@ -37,10 +41,9 @@ public StartAppAction(String param, NotificationAction notification) { @Override public String execute(Context context) { try { - Intent newIntent = new Intent(Intent.ACTION_MAIN); - newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - newIntent.setPackage(param); - context.startActivity(newIntent); + if (!launchApp(context, param)) { + openApp(context, param); + } } catch (Exception e) { return context.getString(R.string.action_start_application_error); } @@ -56,4 +59,38 @@ public boolean isParamRequired() { public String toString() { return "StartAppAction, app_package: " + param; } + + private boolean launchApp(Context context, String packageName) { + + final PackageManager manager = context.getPackageManager(); + final Intent appLauncherIntent = new Intent(Intent.ACTION_MAIN); + appLauncherIntent.addCategory(Intent.CATEGORY_LAUNCHER); + + List resolveInfos = manager.queryIntentActivities(appLauncherIntent, 0); + if ((null != resolveInfos) && (!resolveInfos.isEmpty())) { + for (ResolveInfo rInfo : resolveInfos) { + String className = rInfo.activityInfo.name.trim(); + String targetPackageName = rInfo.activityInfo.packageName.trim(); + if (packageName.trim().equals(targetPackageName)) { + Intent intent = new Intent(); + intent.setClassName(targetPackageName, className); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + return true; + } + } + } + return false; + } + + private boolean openApp(Context context, String packageName) { + PackageManager manager = context.getPackageManager(); + Intent i = manager.getLaunchIntentForPackage(packageName); + if (i == null) { + return false; + } + i.addCategory(Intent.CATEGORY_LAUNCHER); + context.startActivity(i); + return true; + } } diff --git a/build.gradle b/build.gradle index 6456423..bf7359f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.android.databinding:dataBinder:1.0-rc4' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' }