Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
vitas committed Dec 14, 2016
2 parents 4ec5c48 + db4ae2e commit af2570a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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);
}
Expand All @@ -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<ResolveInfo> 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;
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit af2570a

Please sign in to comment.