Java Code Examples for android.content.pm.PackageManager

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/.

Source file: AboutActivity.java

  34 
vote

private String getVersion(){
  try {
    PackageManager packageManager=getPackageManager();
    PackageInfo packageInfo=packageManager.getPackageInfo(getPackageName(),0);
    return packageInfo.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(Constants.TAG,"Error while fetching app version",e);
    return "?";
  }
}
 

Example 2

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.

Source file: ActivityPicker.java

  34 
vote

/** 
 * Fill the given list with any activities matching the base  {@link Intent}. 
 */
protected void putIntentItems(Intent baseIntent,List<PickAdapter.Item> items){
  PackageManager packageManager=getPackageManager();
  List<ResolveInfo> list=packageManager.queryIntentActivities(baseIntent,0);
  Collections.sort(list,new ResolveInfo.DisplayNameComparator(packageManager));
  final int listSize=list.size();
  for (int i=0; i < listSize; i++) {
    ResolveInfo resolveInfo=list.get(i);
    items.add(new PickAdapter.Item(this,packageManager,resolveInfo));
  }
}
 

Example 3

From project Airports, under directory /src/com/nadmm/airports/utils/.

Source file: SystemUtils.java

  32 
vote

public static boolean canDisplayMimeType(Context context,String mimeType){
  PackageManager pm=context.getPackageManager();
  Intent intent=new Intent(Intent.ACTION_VIEW);
  intent.setType(mimeType);
  List<ResolveInfo> list=pm.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);
  return !list.isEmpty();
}
 

Example 4

From project and-bible, under directory /AndBible/src/net/bible/service/common/.

Source file: CommonUtils.java

  32 
vote

public static String getApplicationVersionName(){
  String versionName=null;
  try {
    PackageManager manager=BibleApplication.getApplication().getPackageManager();
    PackageInfo info=manager.getPackageInfo(BibleApplication.getApplication().getPackageName(),0);
    versionName=info.versionName;
  }
 catch (  final NameNotFoundException e) {
    Log.e(TAG,"Error getting package name.",e);
    versionName="Error";
  }
  return versionName;
}
 

Example 5

From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/synchronisation/tracks/.

Source file: WebClient.java

  32 
vote

public WebClient(Context context,String tracksUser,String tracksPassword) throws ApiException {
  this.tracksUser=tracksUser;
  this.tracksPassword=tracksPassword;
  PackageManager manager=context.getPackageManager();
  PackageInfo info=null;
  try {
    info=manager.getPackageInfo(context.getPackageName(),0);
  }
 catch (  PackageManager.NameNotFoundException ignored) {
  }
  if (info != null) {
    sUserAgent=String.format("%1$s %2$s",info.packageName,info.versionName);
  }
}
 

Example 6

From project Android-Terminal-Emulator, under directory /examples/pathbroadcasts/src/jackpal/androidterm/sample/pathbroadcasts/.

Source file: PathReceiver.java

  32 
vote

private String getDataDir(Context context){
  String packageName=context.getPackageName();
  PackageManager pm=context.getPackageManager();
  String dataDir=null;
  try {
    dataDir=pm.getApplicationInfo(packageName,0).dataDir;
  }
 catch (  Exception e) {
  }
  return dataDir;
}
 

Example 7

From project android-tether, under directory /src/og/android/tether/.

Source file: TetherApplication.java

  32 
vote

private boolean isPackageInstalled(String packageName){
  PackageManager packageManager=getPackageManager();
  boolean installed=false;
  try {
    packageManager.getPackageInfo(packageName,PackageManager.GET_ACTIVITIES);
    installed=true;
  }
 catch (  PackageManager.NameNotFoundException e) {
  }
  return installed;
}
 

Example 8

From project android-xbmcremote-sandbox, under directory /src/org/xbmc/android/util/.

Source file: UIUtils.java

  32 
vote

public static Drawable getIconForIntent(final Context context,Intent i){
  PackageManager pm=context.getPackageManager();
  List<ResolveInfo> infos=pm.queryIntentActivities(i,PackageManager.MATCH_DEFAULT_ONLY);
  if (infos.size() > 0) {
    return infos.get(0).loadIcon(pm);
  }
  return null;
}
 

Example 9

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/scan/.

Source file: ScanIntent.java

  32 
vote

public static boolean isInstalled(Context context){
  final PackageManager packageManager=context.getPackageManager();
  final Intent intent=new Intent(INTENT_ACTION_SCAN);
  List<ResolveInfo> list=packageManager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);
  return list.size() > 0;
}
 

Example 10

From project Android_1, under directory /LeftNavBarExample/LeftNavBarLibrary/src/com/example/google/tv/leftnavbar/.

Source file: HomeDisplay.java

  32 
vote

HomeDisplay(Context context,ViewGroup parent,TypedArray attributes){
  mContext=context;
  mMode=Mode.ICON;
  ApplicationInfo appInfo=context.getApplicationInfo();
  PackageManager pm=context.getPackageManager();
  loadLogo(attributes,pm,appInfo);
  loadIcon(attributes,pm,appInfo);
  createView(parent,attributes);
}
 

Example 11

From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/utils/.

Source file: ShortcutPickHelper.java

  32 
vote

private String getFriendlyActivityName(Intent intent,boolean labelOnly){
  PackageManager pm=mParent.getPackageManager();
  ActivityInfo ai=intent.resolveActivityInfo(pm,PackageManager.GET_ACTIVITIES);
  String friendlyName=null;
  if (ai != null) {
    friendlyName=ai.loadLabel(pm).toString();
    if (friendlyName == null && !labelOnly) {
      friendlyName=ai.name;
    }
  }
  return friendlyName != null || labelOnly ? friendlyName : intent.toUri(0);
}
 

Example 12

From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/util/.

Source file: GalleryUtils.java

  32 
vote

public static boolean isEditorAvailable(Context context,String mimeType){
  int version=PackagesMonitor.getPackagesVersion(context);
  String updateKey=PREFIX_PHOTO_EDITOR_UPDATE + mimeType;
  String hasKey=PREFIX_HAS_PHOTO_EDITOR + mimeType;
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context);
  if (prefs.getInt(updateKey,0) != version) {
    PackageManager packageManager=context.getPackageManager();
    List<ResolveInfo> infos=packageManager.queryIntentActivities(new Intent(Intent.ACTION_EDIT).setType(mimeType),0);
    prefs.edit().putInt(updateKey,version).putBoolean(hasKey,!infos.isEmpty()).commit();
  }
  return prefs.getBoolean(hasKey,true);
}
 

Example 13

From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.

Source file: NfcService.java

  32 
vote

void updatePackageCache(){
  PackageManager pm=getPackageManager();
  List<PackageInfo> packages=pm.getInstalledPackages(0);
synchronized (this) {
    mInstalledPackages=packages;
  }
}
 

Example 14

From project android_packages_apps_phone, under directory /src/com/android/phone/.

Source file: PhoneUtils.java

  32 
vote

/** 
 * Get the provider's label from the intent.
 * @param context to lookup the provider's package name.
 * @param intent with an extra set to the provider's package name.
 * @return The provider's application label. null if an erroroccurred during the lookup of the package name or the label.
 */
static CharSequence getProviderLabel(Context context,Intent intent){
  String packageName=intent.getStringExtra(InCallScreen.EXTRA_GATEWAY_PROVIDER_PACKAGE);
  PackageManager pm=context.getPackageManager();
  try {
    ApplicationInfo info=pm.getApplicationInfo(packageName,0);
    return pm.getApplicationLabel(info);
  }
 catch (  PackageManager.NameNotFoundException e) {
    return null;
  }
}
 

Example 15

From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/.

Source file: QsbApplication.java

  32 
vote

public int getVersionCode(){
  if (mVersionCode == 0) {
    try {
      PackageManager pm=getContext().getPackageManager();
      PackageInfo pkgInfo=pm.getPackageInfo(getContext().getPackageName(),0);
      mVersionCode=pkgInfo.versionCode;
    }
 catch (    PackageManager.NameNotFoundException ex) {
      throw new RuntimeException(ex);
    }
  }
  return mVersionCode;
}
 

Example 16

From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/util/.

Source file: Util.java

  32 
vote

public static String getUidName(Context c,int uid,boolean withUid){
  PackageManager pm=c.getPackageManager();
  String uidName="";
  if (uid == 0) {
    uidName="root";
  }
 else {
    pm.getNameForUid(uid);
  }
  if (withUid) {
    uidName+=" (" + uid + ")";
  }
  return uidName;
}
 

Example 17

From project android_packages_apps_Tag, under directory /src/com/android/apps/tag/record/.

Source file: UriRecord.java

  32 
vote

/** 
 * Returns a view in a list of record types for adding new records to a message.
 */
public static View getAddView(Context context,LayoutInflater inflater,ViewGroup parent){
  ViewGroup root=(ViewGroup)inflater.inflate(R.layout.tag_add_record_list_item,parent,false);
  Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
  PackageManager pm=context.getPackageManager();
  List<ResolveInfo> activities=pm.queryIntentActivities(intent,0);
  if (activities.isEmpty()) {
    return null;
  }
  ResolveInfo info=activities.get(0);
  ((ImageView)root.findViewById(R.id.image)).setImageDrawable(info.loadIcon(pm));
  ((TextView)root.findViewById(R.id.text)).setText(context.getString(R.string.url));
  root.setTag(new UriRecordEditInfo(""));
  return root;
}
 

Example 18

From project Anki-Android, under directory /src/com/ichi2/anki/.

Source file: Utils.java

  32 
vote

/** 
 * Indicates whether the specified action can be used as an intent. This method queries the package manager for installed packages that can respond to an intent with the specified action. If no suitable package is found, this method returns false.
 * @param context The application's environment.
 * @param action The Intent action to check for availability.
 * @return True if an Intent with the specified action can be sent and responded to, false otherwise.
 */
public static boolean isIntentAvailable(Context context,String action){
  final PackageManager packageManager=context.getPackageManager();
  final Intent intent=new Intent(action);
  List<ResolveInfo> list=packageManager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);
  return list.size() > 0;
}
 

Example 19

From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/devicespecific/.

Source file: FactoryView_V7.java

  32 
vote

@Override public MultiTouchSupportLevel getMultiTouchSupportLevel(Context appContext){
  PackageManager pkg=appContext.getPackageManager();
  boolean hasMultitouch=pkg.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
  if (hasMultitouch)   return MultiTouchSupportLevel.Basic;
 else   return MultiTouchSupportLevel.None;
}
 

Example 20

From project apps-for-android, under directory /BTClickLinkCompete/src/net/clc/bt/.

Source file: ConnectionService.java

  32 
vote

public int getVersion() throws RemoteException {
  try {
    PackageManager pm=mSelf.getPackageManager();
    PackageInfo pInfo=pm.getPackageInfo(mSelf.getPackageName(),0);
    return pInfo.versionCode;
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"NameNotFoundException in getVersion",e);
  }
  return 0;
}
 

Example 21

From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  32 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 22

From project BazaarUtils, under directory /src/com/congenialmobile/adad/.

Source file: AdView.java

  32 
vote

/** 
 * Checks whether Bazaar client is installed on this or not.
 * @return true if Bazaar is installed on this device.
 */
private boolean isBazaarInstalled(){
  PackageManager pm=mContext.getPackageManager();
  try {
    pm.getApplicationInfo("com.farsitel.bazaar",0);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  return true;
}
 

Example 23

From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/service/.

Source file: SyncService.java

  32 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 24

From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/beintoosdkutility/.

Source file: DeviceId.java

  32 
vote

public static String getAndroidId(Context context){
  String androidId=null;
  try {
    PackageManager pm=context.getPackageManager();
    if (PackageManager.PERMISSION_GRANTED == pm.checkPermission(Manifest.permission.READ_PHONE_STATE,context.getPackageName())) {
      androidId=android.provider.Settings.Secure.getString(context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID);
    }
  }
 catch (  Exception e) {
    return null;
  }
  return androidId;
}
 

Example 25

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenu.java

  31 
vote

public int addIntentOptions(int groupId,int itemId,int order,ComponentName caller,Intent[] specifics,Intent intent,int flags,MenuItem[] outSpecificItems){
  PackageManager pm=mContext.getPackageManager();
  final List<ResolveInfo> lri=pm.queryIntentActivityOptions(caller,specifics,intent,0);
  final int N=lri != null ? lri.size() : 0;
  if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
    removeGroup(groupId);
  }
  for (int i=0; i < N; i++) {
    final ResolveInfo ri=lri.get(i);
    Intent rintent=new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
    rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
    final MenuItem item=add(groupId,itemId,order,ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
    if (outSpecificItems != null && ri.specificIndex >= 0) {
      outSpecificItems[ri.specificIndex]=item;
    }
  }
  return N;
}
 

Example 26

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenu.java

  31 
vote

public int addIntentOptions(int groupId,int itemId,int order,ComponentName caller,Intent[] specifics,Intent intent,int flags,MenuItem[] outSpecificItems){
  PackageManager pm=mContext.getPackageManager();
  final List<ResolveInfo> lri=pm.queryIntentActivityOptions(caller,specifics,intent,0);
  final int N=lri != null ? lri.size() : 0;
  if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
    removeGroup(groupId);
  }
  for (int i=0; i < N; i++) {
    final ResolveInfo ri=lri.get(i);
    Intent rintent=new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
    rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
    final MenuItem item=add(groupId,itemId,order,ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
    if (outSpecificItems != null && ri.specificIndex >= 0) {
      outSpecificItems[ri.specificIndex]=item;
    }
  }
  return N;
}
 

Example 27

From project ActionBarCompat, under directory /ActionBarCompat/src/sk/m217/actionbarcompat/.

Source file: ActionBarHelperBase.java

  31 
vote

/** 
 * Sets up the compatibility action bar with the given title.
 */
private void setupActionBar(){
  final ViewGroup actionBarCompat=getActionBarCompat();
  if (actionBarCompat == null) {
    return;
  }
  mHomeItem=new SimpleMenuItem(new SimpleMenu(mActivity),android.R.id.home,0,mActivity.getTitle());
  final LayoutInflater inflater=LayoutInflater.from(mActivity);
  mHomeLayout=(HomeView)inflater.inflate(R.layout.actionbar_compat_home,actionBarCompat,false);
  mHomeLayout.setOnClickListener(mUpClickListener);
  mHomeLayout.setClickable(true);
  mHomeLayout.setFocusable(true);
  mExpandedHomeLayout=(HomeView)inflater.inflate(R.layout.actionbar_compat_home,actionBarCompat,false);
  mExpandedHomeLayout.setUp(true);
  mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
  mExpandedHomeLayout.setContentDescription(mActivity.getResources().getText(R.string.action_bar_up_description));
  mExpandedHomeLayout.setFocusable(true);
  ApplicationInfo appInfo=mActivity.getApplicationInfo();
  PackageManager pm=mActivity.getPackageManager();
  try {
    mIcon=pm.getActivityIcon(mActivity.getComponentName());
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Activity component name not found!",e);
  }
  if (mIcon == null) {
    mIcon=appInfo.loadIcon(pm);
  }
  mHomeLayout.setIcon(mIcon);
  actionBarCompat.addView(mHomeLayout);
  LinearLayout.LayoutParams springLayoutParams=new LinearLayout.LayoutParams(0,ViewGroup.LayoutParams.FILL_PARENT);
  springLayoutParams.weight=1;
  mTitle=mActivity.getTitle();
  mTitleText=new TextView(mActivity,null,R.attr.actionbarCompatTitleStyle);
  mTitleText.setLayoutParams(springLayoutParams);
  mTitleText.setText(mTitle);
  actionBarCompat.addView(mTitleText);
  setDisplayOptions(DISPLAY_SHOW_HOME | DISPLAY_SHOW_TITLE);
}
 

Example 28

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenu.java

  31 
vote

public int addIntentOptions(int groupId,int itemId,int order,ComponentName caller,Intent[] specifics,Intent intent,int flags,MenuItem[] outSpecificItems){
  PackageManager pm=mContext.getPackageManager();
  final List<ResolveInfo> lri=pm.queryIntentActivityOptions(caller,specifics,intent,0);
  final int N=lri != null ? lri.size() : 0;
  if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
    removeGroup(groupId);
  }
  for (int i=0; i < N; i++) {
    final ResolveInfo ri=lri.get(i);
    Intent rintent=new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
    rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
    final MenuItem item=add(groupId,itemId,order,ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
    if (outSpecificItems != null && ri.specificIndex >= 0) {
      outSpecificItems[ri.specificIndex]=item;
    }
  }
  return N;
}
 

Example 29

From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenu.java

  31 
vote

public int addIntentOptions(int groupId,int itemId,int order,ComponentName caller,Intent[] specifics,Intent intent,int flags,MenuItem[] outSpecificItems){
  PackageManager pm=mContext.getPackageManager();
  final List<ResolveInfo> lri=pm.queryIntentActivityOptions(caller,specifics,intent,0);
  final int N=lri != null ? lri.size() : 0;
  if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
    removeGroup(groupId);
  }
  for (int i=0; i < N; i++) {
    final ResolveInfo ri=lri.get(i);
    Intent rintent=new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
    rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
    final MenuItem item=add(groupId,itemId,order,ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
    if (outSpecificItems != null && ri.specificIndex >= 0) {
      outSpecificItems[ri.specificIndex]=item;
    }
  }
  return N;
}
 

Example 30

From project andlytics, under directory /actionbarsherlock/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenu.java

  31 
vote

public int addIntentOptions(int groupId,int itemId,int order,ComponentName caller,Intent[] specifics,Intent intent,int flags,MenuItem[] outSpecificItems){
  PackageManager pm=mContext.getPackageManager();
  final List<ResolveInfo> lri=pm.queryIntentActivityOptions(caller,specifics,intent,0);
  final int N=lri != null ? lri.size() : 0;
  if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
    removeGroup(groupId);
  }
  for (int i=0; i < N; i++) {
    final ResolveInfo ri=lri.get(i);
    Intent rintent=new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
    rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
    final MenuItem item=add(groupId,itemId,order,ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
    if (outSpecificItems != null && ri.specificIndex >= 0) {
      outSpecificItems[ri.specificIndex]=item;
    }
  }
  return N;
}
 

Example 31

From project android-thaiime, under directory /latinime/src/com/sugree/inputmethod/latin/.

Source file: DictionaryPackInstallBroadcastReceiver.java

  31 
vote

@Override public void onReceive(Context context,Intent intent){
  final String action=intent.getAction();
  final PackageManager manager=context.getPackageManager();
  if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
    final Uri packageUri=intent.getData();
    if (null == packageUri)     return;
    final String packageName=packageUri.getSchemeSpecificPart();
    if (null == packageName)     return;
    final PackageInfo packageInfo;
    try {
      packageInfo=manager.getPackageInfo(packageName,PackageManager.GET_PROVIDERS);
    }
 catch (    android.content.pm.PackageManager.NameNotFoundException e) {
      return;
    }
    final ProviderInfo[] providers=packageInfo.providers;
    if (null == providers)     return;
    for (    ProviderInfo info : providers) {
      if (BinaryDictionary.DICTIONARY_PACK_AUTHORITY.equals(info.authority)) {
        mService.resetSuggestMainDict();
        return;
      }
    }
    return;
  }
 else   if (action.equals(Intent.ACTION_PACKAGE_REMOVED) && !intent.getBooleanExtra(Intent.EXTRA_REPLACING,false)) {
    mService.resetSuggestMainDict();
  }
 else   if (action.equals(NEW_DICTIONARY_INTENT_ACTION)) {
    mService.resetSuggestMainDict();
  }
}
 

Example 32

From project android-wheel, under directory /wheel-demo/src/kankan/wheel/demo/.

Source file: WheelDemo.java

  31 
vote

protected List getData(String prefix){
  List<Map> myData=new ArrayList<Map>();
  Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
  mainIntent.addCategory("kankan.wheel.WHEEL_SAMPLE");
  PackageManager pm=getPackageManager();
  List<ResolveInfo> list=pm.queryIntentActivities(mainIntent,0);
  if (null == list)   return myData;
  String[] prefixPath;
  if (prefix.equals("")) {
    prefixPath=null;
  }
 else {
    prefixPath=prefix.split("/");
  }
  int len=list.size();
  Map<String,Boolean> entries=new HashMap<String,Boolean>();
  for (int i=0; i < len; i++) {
    ResolveInfo info=list.get(i);
    CharSequence labelSeq=info.loadLabel(pm);
    String label=labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
    if (prefix.length() == 0 || label.startsWith(prefix)) {
      String[] labelPath=label.split("/");
      String nextLabel=prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
      if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
        addItem(myData,nextLabel,activityIntent(info.activityInfo.applicationInfo.packageName,info.activityInfo.name));
      }
 else {
        if (entries.get(nextLabel) == null) {
          addItem(myData,nextLabel,browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
          entries.put(nextLabel,true);
        }
      }
    }
  }
  Collections.sort(myData,sDisplayNameComparator);
  return myData;
}
 

Example 33

From project android-wheel-datetime-picker, under directory /src/kankan/wheel/demo/.

Source file: WheelDemo.java

  31 
vote

protected List getData(String prefix){
  List<Map<String,Object>> myData=new ArrayList<Map<String,Object>>();
  Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
  mainIntent.addCategory("kankan.wheel.WHEEL_SAMPLE");
  PackageManager pm=getPackageManager();
  List<ResolveInfo> list=pm.queryIntentActivities(mainIntent,0);
  if (null == list)   return myData;
  String[] prefixPath;
  if (prefix.equals("")) {
    prefixPath=null;
  }
 else {
    prefixPath=prefix.split("/");
  }
  int len=list.size();
  Map<String,Boolean> entries=new HashMap<String,Boolean>();
  for (int i=0; i < len; i++) {
    ResolveInfo info=list.get(i);
    CharSequence labelSeq=info.loadLabel(pm);
    String label=labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
    if (prefix.length() == 0 || label.startsWith(prefix)) {
      String[] labelPath=label.split("/");
      String nextLabel=prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
      if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
        addItem(myData,nextLabel,activityIntent(info.activityInfo.applicationInfo.packageName,info.activityInfo.name));
      }
 else {
        if (entries.get(nextLabel) == null) {
          addItem(myData,nextLabel,browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
          entries.put(nextLabel,true);
        }
      }
    }
  }
  Collections.sort(myData,sDisplayNameComparator);
  return myData;
}
 

Example 34

From project android-wheel_1, under directory /wheel-demo/src/kankan/wheel/demo/.

Source file: WheelDemo.java

  31 
vote

protected List getData(String prefix){
  List<Map> myData=new ArrayList<Map>();
  Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
  mainIntent.addCategory("kankan.wheel.WHEEL_SAMPLE");
  PackageManager pm=getPackageManager();
  List<ResolveInfo> list=pm.queryIntentActivities(mainIntent,0);
  if (null == list)   return myData;
  String[] prefixPath;
  if (prefix.equals("")) {
    prefixPath=null;
  }
 else {
    prefixPath=prefix.split("/");
  }
  int len=list.size();
  Map<String,Boolean> entries=new HashMap<String,Boolean>();
  for (int i=0; i < len; i++) {
    ResolveInfo info=list.get(i);
    CharSequence labelSeq=info.loadLabel(pm);
    String label=labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
    if (prefix.length() == 0 || label.startsWith(prefix)) {
      String[] labelPath=label.split("/");
      String nextLabel=prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
      if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
        addItem(myData,nextLabel,activityIntent(info.activityInfo.applicationInfo.packageName,info.activityInfo.name));
      }
 else {
        if (entries.get(nextLabel) == null) {
          addItem(myData,nextLabel,browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
          entries.put(nextLabel,true);
        }
      }
    }
  }
  Collections.sort(myData,sDisplayNameComparator);
  return myData;
}
 

Example 35

From project AndroidCommon, under directory /src/com/asksven/android/common/nameutils/.

Source file: UidNameResolver.java

  31 
vote

public String getLabel(Context context,String packageName){
  String ret=packageName;
  PackageManager pm=context.getPackageManager();
  try {
    ApplicationInfo ai=pm.getApplicationInfo(packageName,0);
    CharSequence label=ai.loadLabel(pm);
    if (label != null) {
      ret=label.toString();
    }
  }
 catch (  NameNotFoundException e) {
    ret=packageName;
  }
  return ret;
}
 

Example 36

From project AndroidLab, under directory /src/src/de/tubs/ibr/android/ldap/core/activities/.

Source file: EditContactActivity.java

  31 
vote

/** 
 * @param name The name of the account. This is usually the user's email address or username.
 * @param description The description for this account. This will be dictated by the type of account returned, and can be obtained from the system AccountManager.
 */
public AccountData(String name,AuthenticatorDescription description){
  mName=name;
  if (description != null) {
    mType=description.type;
    String packageName=description.packageName;
    PackageManager pm=getPackageManager();
    if (description.labelId != 0) {
      mTypeLabel=pm.getText(packageName,description.labelId,null);
      if (mTypeLabel == null) {
        throw new IllegalArgumentException("LabelID provided, but label not found");
      }
    }
 else {
      mTypeLabel="";
    }
    if (description.iconId != 0) {
      mIcon=pm.getDrawable(packageName,description.iconId,null);
      if (mIcon == null) {
        throw new IllegalArgumentException("IconID provided, but drawable not " + "found");
      }
    }
 else {
      mIcon=getResources().getDrawable(android.R.drawable.sym_def_app_icon);
    }
  }
}
 

Example 37

From project androidquery, under directory /auth/com/androidquery/auth/.

Source file: FacebookHandle.java

  31 
vote

private boolean validateAppSignatureForIntent(Context context,Intent intent){
  PackageManager pm=context.getPackageManager();
  ResolveInfo resolveInfo=pm.resolveActivity(intent,0);
  if (resolveInfo == null) {
    return false;
  }
  String packageName=resolveInfo.activityInfo.packageName;
  PackageInfo packageInfo;
  try {
    packageInfo=pm.getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 38

From project androidZenWriter, under directory /library/src/com/actionbarsherlock/internal/view/menu/.

Source file: ActionMenu.java

  31 
vote

public int addIntentOptions(int groupId,int itemId,int order,ComponentName caller,Intent[] specifics,Intent intent,int flags,MenuItem[] outSpecificItems){
  PackageManager pm=mContext.getPackageManager();
  final List<ResolveInfo> lri=pm.queryIntentActivityOptions(caller,specifics,intent,0);
  final int N=lri != null ? lri.size() : 0;
  if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
    removeGroup(groupId);
  }
  for (int i=0; i < N; i++) {
    final ResolveInfo ri=lri.get(i);
    Intent rintent=new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
    rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
    final MenuItem item=add(groupId,itemId,order,ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
    if (outSpecificItems != null && ri.specificIndex >= 0) {
      outSpecificItems[ri.specificIndex]=item;
    }
  }
  return N;
}
 

Example 39

From project android_packages_apps_CMSettings, under directory /src/com/cyanogenmod/settings/activities/.

Source file: PowerWidget.java

  31 
vote

public ButtonAdapter(Context c){
  mContext=c;
  mInflater=LayoutInflater.from(mContext);
  PackageManager pm=mContext.getPackageManager();
  if (pm != null) {
    try {
      mSystemUIResources=pm.getResourcesForApplication("com.android.systemui");
    }
 catch (    Exception e) {
      mSystemUIResources=null;
      Log.e(TAG,"Could not load SystemUI resources",e);
    }
  }
  reloadButtons();
}
 

Example 40

From project android_packages_apps_FileManager, under directory /src/org/openintents/filemanager/.

Source file: FileManagerActivity.java

  31 
vote

/** 
 * @since 2011-09-30
 */
private void showMoreCommandsDialog(){
  final Uri data=Uri.fromFile(mContextFile);
  final Intent intent=new Intent(null,data);
  String type=mMimeTypes.getMimeType(mContextFile.getName());
  intent.setDataAndType(data,type);
  Log.v(TAG,"Data=" + data);
  Log.v(TAG,"Type=" + type);
  if (type != null) {
    PackageManager pm=getPackageManager();
    final List<ResolveInfo> lri=pm.queryIntentActivityOptions(new ComponentName(this,FileManagerActivity.class),null,intent,0);
    final int N=lri != null ? lri.size() : 0;
    final List<CharSequence> items=new ArrayList<CharSequence>();
    List<ResolveInfo> toRemove=new ArrayList<ResolveInfo>();
    for (int i=0; i < N; i++) {
      final ResolveInfo ri=lri.get(i);
      Intent rintent=new Intent(intent);
      rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
      ActivityInfo info=rintent.resolveActivityInfo(pm,0);
      String permission=info.permission;
      if (info.exported && (permission == null || checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED))       items.add(ri.loadLabel(pm));
 else       toRemove.add(ri);
    }
    for (    ResolveInfo ri : toRemove) {
      lri.remove(ri);
    }
    new AlertDialog.Builder(this).setTitle(mContextText).setIcon(mContextIcon).setItems(items.toArray(new CharSequence[0]),new DialogInterface.OnClickListener(){
      public void onClick(      DialogInterface dialog,      int item){
        final ResolveInfo ri=lri.get(item);
        Intent rintent=new Intent(intent).setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName,ri.activityInfo.name));
        startActivity(rintent);
      }
    }
).create().show();
  }
}
 

Example 41

From project android_packages_apps_SalvageParts, under directory /src/com/salvagemod/salvageparts/activities/.

Source file: PowerWidgetOrderActivity.java

  31 
vote

public ButtonAdapter(Context c){
  mContext=c;
  mInflater=LayoutInflater.from(mContext);
  PackageManager pm=mContext.getPackageManager();
  if (pm != null) {
    try {
      mSystemUIResources=pm.getResourcesForApplication("com.android.systemui");
    }
 catch (    Exception e) {
      mSystemUIResources=null;
      Log.e(TAG,"Could not load SystemUI resources",e);
    }
  }
  reloadButtons();
}
 

Example 42

From project android_packages_apps_TouchWiz30Launcher, under directory /src/com/sec/android/app/twlauncher/.

Source file: LauncherProvider.java

  31 
vote

private boolean loadCustomerMainApps(SQLiteDatabase sqlitedatabase){
  mCustomer=LauncherCustomer.getInstance("default_mainapplication_order.xml",2);
  int i=mCustomer.getCustomerCount();
  boolean flag;
  if (i <= 0) {
    flag=false;
  }
 else {
    (new Intent("android.intent.action.MAIN",null)).addCategory("android.intent.category.LAUNCHER");
    ContentValues contentvalues=new ContentValues();
    PackageManager packagemanager=mContext.getPackageManager();
    for (int j=0; j < i; j++) {
      String as[]=new String[2];
      mCustomer.getCustomerMainAppInfo(j,as);
      contentvalues.clear();
      addCSCMainApp(sqlitedatabase,contentvalues,as[0],as[1],menuIndexfromCSC,packagemanager);
      menuIndexfromCSC=1 + menuIndexfromCSC;
    }
    flag=true;
  }
  return flag;
}
 

Example 43

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/latin/.

Source file: DictionaryPackInstallBroadcastReceiver.java

  31 
vote

@Override public void onReceive(Context context,Intent intent){
  final String action=intent.getAction();
  final PackageManager manager=context.getPackageManager();
  if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
    final Uri packageUri=intent.getData();
    if (null == packageUri)     return;
    final String packageName=packageUri.getSchemeSpecificPart();
    if (null == packageName)     return;
    final PackageInfo packageInfo;
    try {
      packageInfo=manager.getPackageInfo(packageName,PackageManager.GET_PROVIDERS);
    }
 catch (    android.content.pm.PackageManager.NameNotFoundException e) {
      return;
    }
    final ProviderInfo[] providers=packageInfo.providers;
    if (null == providers)     return;
    for (    ProviderInfo info : providers) {
      if (BinaryDictionary.DICTIONARY_PACK_AUTHORITY.equals(info.authority)) {
        mService.resetSuggestMainDict();
        return;
      }
    }
    return;
  }
 else   if (action.equals(Intent.ACTION_PACKAGE_REMOVED) && !intent.getBooleanExtra(Intent.EXTRA_REPLACING,false)) {
    mService.resetSuggestMainDict();
  }
 else   if (action.equals(NEW_DICTIONARY_INTENT_ACTION)) {
    mService.resetSuggestMainDict();
  }
}
 

Example 44

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/.

Source file: AboutActivity.java

  29 
vote

public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.about);
  TextView versionTextView=(TextView)findViewById(R.id.version);
  TextView buildTimeTextView=(TextView)findViewById(R.id.build_time);
  TextView authorTextView=(TextView)findViewById(R.id.author);
  setTitle("About Amenoid");
  String myPackageName=this.getPackageName();
  int versionCode=0;
  String versionName=null;
  try {
    PackageInfo packageInfo=this.getPackageManager().getPackageInfo(myPackageName,0);
    versionName=packageInfo.versionName;
    versionCode=packageInfo.versionCode;
  }
 catch (  PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  versionTextView.setText("Version: " + versionName + " ("+ versionCode+ ")");
  authorTextView.setText("Author: Dirk Jaeckel <amenoid@dirk.jaeckel.name>\n");
  final String timestampString=getResources().getString(R.string.buildtimestamp);
  buildTimeTextView.setText("Built: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Long.valueOf(timestampString)));
}
 

Example 45

From project android-bankdroid, under directory /src/com/liato/bankdroid/.

Source file: AboutActivity.java

  29 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.about);
  PackageInfo pInfo;
  String version="v1.x.x";
  try {
    pInfo=getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_META_DATA);
    version=pInfo.versionName;
  }
 catch (  final NameNotFoundException e) {
    e.printStackTrace();
  }
  ((TextView)findViewById(R.id.txtVersion)).setText(getText(R.string.version).toString().replace("$version",version));
  this.addTitleButton(R.drawable.title_icon_donate,"donate",this);
  this.addTitleButton(R.drawable.title_icon_web,"web",this);
}
 

Example 46

From project android-client, under directory /xwiki-android-client/src/org/xwiki/android/client/launcher/.

Source file: IconLaunchPad.java

  29 
vote

public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.launchpad);
  GridView gridview=(GridView)findViewById(R.id.gv_launchpad);
  gridview.setNumColumns(3);
  Intent intent=new Intent(XWikiIntentFilters.ACTION_MAIN);
  List<ResolveInfo> list=getPackageManager().queryIntentActivities(intent,PackageManager.GET_ACTIVITIES);
  List<ImageButton> imgBtns=new ArrayList<ImageButton>();
  int i=0;
  for (  ResolveInfo r : list) {
    int iconId=r.getIconResource();
    ImageButton btn=new ImageButton(this);
    btn.setImageResource(iconId);
    btn.setBackgroundColor(Color.TRANSPARENT);
    imgBtns.add(btn);
    Log.d(this.getClass().getSimpleName(),"Btn for:" + r.activityInfo.name + "icon id is:"+ iconId);
    btn.setTag(r.activityInfo.name);
    btn.setOnClickListener(this);
    i++;
  }
  ImgBtnAdapter adapter=new ImgBtnAdapter(imgBtns);
  gridview.setAdapter(adapter);
}
 

Example 47

From project android-context, under directory /defunct/.

Source file: PrefsActivity.java

  29 
vote

public static String getVersion(Context context){
  String version="1.0";
  try {
    PackageInfo pi=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    version=pi.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(TAG,"Package name not found",e);
  }
  return version;
}
 

Example 48

From project Android-File-Manager, under directory /src/com/nexes/manager/.

Source file: ApplicationBackup.java

  29 
vote

private void get_downloaded_apps(){
  List<ApplicationInfo> all_apps=mPackMag.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
  for (  ApplicationInfo appInfo : all_apps) {
    if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && (appInfo.flags & FLAG_UPDATED_SYS_APP) == 0 && appInfo.flags != 0)     mAppList.add(appInfo);
  }
  mAppLabel.setText("You have " + mAppList.size() + " downloaded apps");
}
 

Example 49

From project android-joedayz, under directory /Proyectos/FBConnectTest/src/com/facebook/android/.

Source file: Facebook.java

  29 
vote

/** 
 * Query the signature for the application that would be invoked by the given intent and verify that it matches the FB application's signature.
 * @param context
 * @param packageName
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForPackage(Context context,String packageName){
  PackageInfo packageInfo;
  try {
    packageInfo=context.getPackageManager().getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 50

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: CaptureActivity.java

  29 
vote

/** 
 * We want the help screen to be shown automatically the first time a new version of the app is run. The easiest way to do this is to check android:versionCode from the manifest, and compare it to a value stored as a preference.
 */
private boolean checkFirstLaunch(){
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    int currentVersion=info.versionCode;
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
    int lastVersion=prefs.getInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,0);
    if (lastVersion == 0) {
      isFirstLaunch=true;
    }
 else {
      isFirstLaunch=false;
    }
    if (currentVersion > lastVersion) {
      prefs.edit().putInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,currentVersion).commit();
      Intent intent=new Intent(this,HelpActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      String page=lastVersion == 0 ? HelpActivity.DEFAULT_PAGE : HelpActivity.WHATS_NEW_PAGE;
      intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY,page);
      startActivity(intent);
      return true;
    }
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.w(TAG,e);
  }
  return false;
}
 

Example 51

From project android-sdk, under directory /src/main/java/com/mobeelizer/mobile/android/.

Source file: MobeelizerApplication.java

  29 
vote

private Bundle getMetaData(final Application mobeelizer){
  try {
    return mobeelizer.getPackageManager().getApplicationInfo(mobeelizer.getPackageName(),PackageManager.GET_META_DATA).metaData;
  }
 catch (  NameNotFoundException e) {
    throw new IllegalStateException(e.getMessage(),e);
  }
}
 

Example 52

From project Android-Simple-Social-Sharing, under directory /SimpleSocialSharing/src/com/nostra13/socialsharing/facebook/extpack/com/facebook/android/.

Source file: Facebook.java

  29 
vote

/** 
 * Query the signature for the application that would be invoked by the given intent and verify that it matches the FB application's signature.
 * @param activity
 * @param intent
 * @param validSignature
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForIntent(Activity activity,Intent intent){
  ResolveInfo resolveInfo=activity.getPackageManager().resolveActivity(intent,0);
  if (resolveInfo == null) {
    return false;
  }
  String packageName=resolveInfo.activityInfo.packageName;
  PackageInfo packageInfo;
  try {
    packageInfo=activity.getPackageManager().getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 53

From project android-voip-service, under directory /src/main/java/net/chrislehmann/sipservice/service/.

Source file: SipService.java

  29 
vote

private void dumpInstalledLinphoneInformation(){
  PackageInfo info=null;
  try {
    info=getPackageManager().getPackageInfo(getPackageName(),0);
  }
 catch (  PackageManager.NameNotFoundException nnfe) {
  }
  if (info != null) {
    org.linphone.core.Log.i("Linphone version is ",info.versionCode);
  }
 else {
    org.linphone.core.Log.i("Linphone version is unknown");
  }
}
 

Example 54

From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/controller/.

Source file: MovieListController.java

  29 
vote

public void onContextItemSelected(MenuItem item){
  final Movie movie=(Movie)mList.getAdapter().getItem(((FiveLabelsItemView)((AdapterContextMenuInfo)item.getMenuInfo()).targetView).position);
switch (item.getItemId()) {
case ITEM_CONTEXT_PLAY:
    mControlManager.playFile(new DataResponse<Boolean>(){
      public void run(){
        if (value) {
          mActivity.startActivity(new Intent(mActivity,NowPlayingActivity.class));
        }
      }
    }
,movie.getPath(),mActivity.getApplicationContext());
  break;
case ITEM_CONTEXT_INFO:
Intent nextActivity=new Intent(mActivity,MovieDetailsActivity.class);
nextActivity.putExtra(ListController.EXTRA_MOVIE,movie);
mActivity.startActivity(nextActivity);
break;
case ITEM_CONTEXT_IMDB:
Intent intentIMDb=null;
if (movie.getIMDbId().equals("")) {
intentIMDb=new Intent(Intent.ACTION_VIEW,Uri.parse("imdb:///find?s=tt&q=" + movie.getName()));
}
 else {
intentIMDb=new Intent(Intent.ACTION_VIEW,Uri.parse("imdb:///title/" + movie.getIMDbId()));
}
if (mActivity.getPackageManager().resolveActivity(intentIMDb,PackageManager.MATCH_DEFAULT_ONLY) == null) {
if (movie.getIMDbId().equals("")) {
intentIMDb=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.imdb.com/search/title?title=" + movie.getShortName() + "&title_type=feature,tv_movie&release_date="+ movie.year));
}
 else {
intentIMDb=new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.imdb.com/title/" + movie.getIMDbId()));
}
}
mActivity.startActivity(intentIMDb);
break;
default :
return;
}
}
 

Example 55

From project androidTileMapEditor_1, under directory /src/it/sineo/android/tileMapEditor/.

Source file: AboutActivity.java

  29 
vote

public View createTabContent(String tag,LayoutInflater inflater){
  Context ctx=inflater.getContext();
  if (TAG_INFO.equals(tag)) {
    View v=inflater.inflate(R.layout.about_info,null,false);
    String version="?";
    try {
      PackageInfo info=ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),0);
      version=info.versionName;
    }
 catch (    PackageManager.NameNotFoundException pmnnfex) {
      pmnnfex.printStackTrace();
    }
    ((TextView)v.findViewById(R.id.about_info_version)).setText(getResources().getString(R.string.about_info_version,version));
    ImageView ivDonate=(ImageView)v.findViewById(R.id.donate_button);
    ivDonate.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse(getString(R.string.paypal_donate_url)));
        startActivity(i);
      }
    }
);
    return v;
  }
 else   if (TAG_CHANGELOG.equals(tag)) {
    return ChangelogFactory.inflate(ctx,R.xml.changelog);
  }
 else   if (TAG_LICENSE.equals(tag)) {
    return createLicenseView(R.raw.license,inflater);
  }
  Log.e(getClass().getName(),"unknown tag: " + tag);
  return null;
}
 

Example 56

From project android_7, under directory /src/org/immopoly/android/helper/.

Source file: LocationHelper.java

  29 
vote

public static void requestLocationSettings(final Context context){
  AlertDialog.Builder builder=new AlertDialog.Builder(context);
  builder.setTitle(R.string.allow_localization_title);
  builder.setMessage(R.string.allow_localization_message);
  builder.setCancelable(true).setNegativeButton(R.string.button_cancel,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
    }
  }
);
  final Intent locationSettingsIntent=new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  final ComponentName toLaunch=new ComponentName("com.android.settings","com.android.settings.SecuritySettings");
  locationSettingsIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  locationSettingsIntent.setComponent(toLaunch);
  locationSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  final Intent generellSettingsIntent=new Intent(Settings.ACTION_SETTINGS);
  builder.setPositiveButton("Einstellungen",new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      if (context.getPackageManager().resolveActivity(locationSettingsIntent,PackageManager.MATCH_DEFAULT_ONLY) != null) {
        context.startActivity(locationSettingsIntent);
      }
 else       if (context.getPackageManager().resolveActivity(generellSettingsIntent,PackageManager.MATCH_DEFAULT_ONLY) != null) {
        context.startActivity(generellSettingsIntent);
      }
 else {
        Toast.makeText(context,context.getString(R.string.allow_localization_message_manuel),Toast.LENGTH_LONG).show();
      }
    }
  }
);
  AlertDialog alert=builder.create();
  alert.show();
}
 

Example 57

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.

Source file: GridInputProcessor.java

  29 
vote

public GridInputProcessor(Context context,GridCamera camera,GridLayer layer,RenderView view,Pool<Vector3f> pool,DisplayItem[] displayItems){
  mPool=pool;
  mCamera=camera;
  mLayer=layer;
  mCurrentFocusSlot=Shared.INVALID;
  mCurrentSelectedSlot=Shared.INVALID;
  mCurrentScaleSlot=Shared.INVALID;
  mContext=context;
  mDisplayItems=displayItems;
  mGestureDetector=new GestureDetector(context,this);
  mScaleGestureDetector=new ScaleGestureDetector(context,this);
  mGestureDetector.setIsLongpressEnabled(true);
  mZoomGesture=false;
  mScale=1.0f;
  mSupportPanAndZoom=context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH);
{
    WindowManager windowManager=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
    mDisplay=windowManager.getDefaultDisplay();
  }
}