/config/src/com/google/marvin/config/Utils.java
Java | 47 lines | 35 code | 5 blank | 7 comment | 0 complexity | 70517ed8d95f62fd00d17dad5f94ce8e MD5 | raw file
1package com.google.marvin.config; 2 3import android.content.Context; 4import android.content.Intent; 5import android.content.pm.PackageManager.NameNotFoundException; 6import android.net.Uri; 7 8/** 9 * A collection of commonly used utility functions. 10 * 11 * @author clchen@google.com (Charles L. Chen) 12 */ 13 14public class Utils { 15 public static boolean applicationInstalled(Context ctx, String packageName) { 16 try { 17 Context myContext = ctx.createPackageContext(packageName, 0); 18 } catch (NameNotFoundException e) { 19 return false; 20 } 21 return true; 22 } 23 24 public static Intent getMarketIntent(String packageName) { 25 Uri marketUri = Uri.parse("market://search?q=pname:" + packageName); 26 Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); 27 return marketIntent; 28 } 29 30 public static Intent getAppStartIntent(Context ctx, String packageName, String className) { 31 Intent intent = null; 32 try { 33 int flags = Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY; 34 Context myContext = ctx.createPackageContext(packageName, flags); 35 Class<?> appClass = myContext.getClassLoader().loadClass(className); 36 intent = new Intent(myContext, appClass); 37 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 38 } catch (NameNotFoundException e) { 39 // TODO Auto-generated catch block 40 e.printStackTrace(); 41 } catch (ClassNotFoundException e) { 42 // TODO Auto-generated catch block 43 e.printStackTrace(); 44 } 45 return intent; 46 } 47}