Created
July 25, 2015 14:28
-
-
Save TheFinestArtist/1779ca82a9e59f5ab26b to your computer and use it in GitHub Desktop.
PackagesHelper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.net.Uri; | |
/** | |
* PackagesHelper | |
* | |
* @author The Finest Artist | |
*/ | |
public class PackagesHelper { | |
public static String KAKAOTALK = "com.kakao.talk"; | |
public static String KAKAOSTORY = "com.kakao.story"; | |
public static String FACEBOOK = "com.facebook.katana"; | |
public static String TWITTER = "com.twitter.android"; | |
public static String GOOGLE_PLUS = "com.google.android.apps.plus"; | |
public static String GMAIL = "com.google.android.gm"; | |
public static String PINTEREST = "com.pinterest"; | |
public static String TUMBLR = "com.tumblr"; | |
public static String FANCY = "com.thefancy.app"; | |
public static String FLIPBOARD = "flipboard.app"; | |
public static boolean isInstalled(Context context, String packageUri) { | |
PackageManager pm = context.getPackageManager(); | |
boolean app_installed; | |
try { | |
pm.getPackageInfo(packageUri, PackageManager.GET_ACTIVITIES); | |
app_installed = true; | |
} catch (PackageManager.NameNotFoundException e) { | |
app_installed = false; | |
} | |
return app_installed; | |
} | |
public static void updateApp(Context context) { | |
final String appPackageName = context.getPackageName(); // getPackageName() from Context or Activity object | |
try { | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)); | |
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
context.startActivity(intent); | |
} catch (android.content.ActivityNotFoundException anfe) { | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)); | |
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
context.startActivity(intent); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment