Java Code Examples for android.content.pm.ResolveInfo#loadIcon()

The following examples show how to use android.content.pm.ResolveInfo#loadIcon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PageApp.java    From TvLauncher with Apache License 2.0 6 votes vote down vote up
public AppInfoVo getApp(ResolveInfo app) {
    AppInfoVo mAppInfo = new AppInfoVo();
    mAppInfo.mAppName = (String) app.loadLabel(mPackManager);
    mAppInfo.mAppPackageName = app.activityInfo.packageName;
    mAppInfo.mAppIcon = app.loadIcon(mPackManager);

    if ((app.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
        mAppInfo.isSystemApps = true;
    } else {
        mAppInfo.isSystemApps = false;
    }

    Intent intent = new Intent();
    intent.setComponent(new ComponentName(app.activityInfo.packageName, app.activityInfo.name));
    mAppInfo.mAppIntent = intent;

    return mAppInfo;
}
 
Example 2
Source File: ThirdPartyWallpaperPickerListAdapter.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
public View getView(int position, View convertView, ViewGroup parent) {
    View view;

    if (convertView == null) {
        view = mInflater.inflate(R.layout.wallpaper_picker_third_party_item, parent, false);
    } else {
        view = convertView;
    }

    ResolveInfo info = mThirdPartyWallpaperPickers.get(position).mResolveInfo;
    TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label);
    label.setText(info.loadLabel(mPackageManager));
    Drawable icon = info.loadIcon(mPackageManager);
    icon.setBounds(new Rect(0, 0, mIconSize, mIconSize));
    label.setCompoundDrawables(null, icon, null, null);
    return view;
}
 
Example 3
Source File: AppManager.java    From shadowsocks-android-java with Apache License 2.0 6 votes vote down vote up
public void queryAppInfo() {
    PackageManager pm = this.getPackageManager(); // 获得PackageManager对象
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(mainIntent, 0);
    Collections.sort(resolveInfos, new ResolveInfo.DisplayNameComparator(pm));
    if (AppProxyManager.Instance.mlistAppInfo != null) {
        AppProxyManager.Instance.mlistAppInfo.clear();
        for (ResolveInfo reInfo : resolveInfos) {
            String pkgName = reInfo.activityInfo.packageName; // 获得应用程序的包名
            String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label
            Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标
            AppInfo appInfo = new AppInfo();
            appInfo.setAppLabel(appLabel);
            appInfo.setPkgName(pkgName);
            appInfo.setAppIcon(icon);
            if (!appInfo.getPkgName().equals("com.vm.shadowsocks"))//App本身会强制加入代理列表
                AppProxyManager.Instance.mlistAppInfo.add(appInfo);
        }
    }
}
 
Example 4
Source File: IntentListAdapter.java    From android-bottomsheet with ISC License 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item_intent, parent, false));
    } else {
        holder = ViewHolder.from(convertView);
    }

    ResolveInfo item = getItem(position);
    holder.text.setText(item.loadLabel(mPackageManager));
    Drawable icon = item.loadIcon(mPackageManager);
    icon.setBounds(0, 0, mIconSize,
            (int) (((float) icon.getIntrinsicHeight()) / icon.getIntrinsicWidth() * mIconSize));
    holder.text.setCompoundDrawables(icon, null, null, null);

    return holder.itemView;
}
 
Example 5
Source File: ThirdPartyWallpaperPickerListAdapter.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
public View getView(int position, View convertView, ViewGroup parent) {
    View view;

    if (convertView == null) {
        view = mInflater.inflate(R.layout.wallpaper_picker_third_party_item, parent, false);
    } else {
        view = convertView;
    }

    WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view);

    ResolveInfo info = mThirdPartyWallpaperPickers.get(position).mResolveInfo;
    TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label);
    label.setText(info.loadLabel(mPackageManager));
    Drawable icon = info.loadIcon(mPackageManager);
    icon.setBounds(new Rect(0, 0, mIconSize, mIconSize));
    label.setCompoundDrawables(null, icon, null, null);
    return view;
}
 
Example 6
Source File: BaseImageDownloader.java    From candybar with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves {@link InputStream} of image by URI (image source from package name).
 *
 * @param imageUri Image URI
 * @param extra    Auxiliary object which was passed to {@link DisplayImageOptions.Builder#extraForDownloader(Object)
 *                 DisplayImageOptions.extraForDownloader(Object)}; can be null
 * @return {@link InputStream} of image
 * @throws IOException if some I/O error occurs
 */
protected InputStream getStreamFromPackage(String imageUri, Object extra) throws IOException {
    PackageManager packageManager = context.getPackageManager();
    String componentName = Scheme.PACKAGE.crop(imageUri);
    Bitmap resBitmap;

    int slashIndex = componentName.indexOf("/");
    String activityName = componentName.substring(slashIndex).replace("/", "");
    String packageName = componentName.replace("/" + activityName, "");

    Intent intent = new Intent();
    intent.setComponent(new ComponentName(packageName, activityName));
    ResolveInfo resolveInfo = packageManager.resolveActivity(intent, 0);
    Drawable drawable = resolveInfo.loadIcon(packageManager);
    resBitmap = getRightIcon(drawable);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    resBitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
    resBitmap.recycle();
    return new ByteArrayInputStream(stream.toByteArray());
}
 
Example 7
Source File: ResolverActivity.java    From container with GNU General Public License v3.0 6 votes vote down vote up
Drawable loadIconForResolveInfo(ResolveInfo ri) {
    Drawable dr;
    try {
        if (ri.resolvePackageName != null && ri.icon != 0) {
            dr = getIcon(mPm.getResourcesForApplication(ri.resolvePackageName), ri.icon);
            if (dr != null) {
                return dr;
            }
        }
        final int iconRes = ri.getIconResource();
        if (iconRes != 0) {
            dr = getIcon(mPm.getResourcesForApplication(ri.activityInfo.packageName), iconRes);
            if (dr != null) {
                return dr;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        VLog.e(TAG, "Couldn't find resources for package\n"+VLog.getStackTraceString(e));
    }
    return ri.loadIcon(mPm);
}
 
Example 8
Source File: ShareDialogAdapter.java    From delion with Apache License 2.0 5 votes vote down vote up
private Drawable loadIconForResolveInfo(ResolveInfo info) {
    try {
        final int iconRes = info.getIconResource();
        if (iconRes != 0) {
            Resources res = mManager.getResourcesForApplication(info.activityInfo.packageName);
            Drawable icon = ApiCompatibilityUtils.getDrawable(res, iconRes);
            return icon;
        }
    } catch (NameNotFoundException | NotFoundException e) {
        // Could not find the icon. loadIcon call below will return the default app icon.
    }
    return info.loadIcon(mManager);
}
 
Example 9
Source File: ShareDialogAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private Drawable loadIconForResolveInfo(ResolveInfo info) {
    try {
        final int iconRes = info.getIconResource();
        if (iconRes != 0) {
            Resources res = mManager.getResourcesForApplication(info.activityInfo.packageName);
            Drawable icon = ApiCompatibilityUtils.getDrawable(res, iconRes);
            return icon;
        }
    } catch (NameNotFoundException | NotFoundException e) {
        // Could not find the icon. loadIcon call below will return the default app icon.
    }
    return info.loadIcon(mManager);
}
 
Example 10
Source File: IntentGridAdapter.java    From android-bottomsheet with ISC License 5 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    final ResolveInfo item = mItems.get(position);
    holder.text.setText(item.activityInfo.loadLabel(mPackageManager));
    Drawable icon = item.loadIcon(mPackageManager);
    icon.setBounds(0, 0, mIconSize,
            (int) (((float) icon.getIntrinsicHeight()) / icon.getIntrinsicWidth() * mIconSize));
    holder.text.setCompoundDrawables(null, icon, null, null);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mOnItemClickedListener.onItemClicked(item);
        }
    });
}
 
Example 11
Source File: AppInfoProvider.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
public AppInfo getSingleInfo(ResolveInfo reInfo, String packageFilter) {
    String pkgName = reInfo.activityInfo.packageName; // Get the package name of the application
    AppInfo appInfo = null;
    if (TextUtils.equals(pkgName, packageFilter) || TextUtils.equals(APP_NO_FILTER, packageFilter)) {
        String activityName = reInfo.activityInfo.name; // Get the name of the startup Activity for the application
        String appLabel = (String) reInfo.loadLabel(mPackageManager); // Get the application Label
        Drawable icon = reInfo.loadIcon(mPackageManager); // Get the application icon
        // Preparing Intent for application startup Activity
        Intent launchIntent = new Intent();
        launchIntent.setComponent(new ComponentName(pkgName,
                activityName));

        // create an AppInfo
        appInfo = new AppInfo();
        appInfo.setPackageName(pkgName);
        appInfo.setAppName(appLabel);
        appInfo.setIcon(icon);
        appInfo.setActivityName(activityName);
        appInfo.setIntent(launchIntent);

        try {
            PackageInfo mPackageInfo = mContext.getPackageManager().getPackageInfo(pkgName, 0);
            if ((mPackageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) {
                // third apps
                appInfo.setSystem(false);
            } else {
                // system apps
                appInfo.setSystem(true);
            }
        } catch (PackageManager.NameNotFoundException e) {
            LogUtil.e("AppInfoProvider", e.getMessage().toString());
        }
    }
    return appInfo;
}
 
Example 12
Source File: PkgUtil.java    From NanoIconPack with Apache License 2.0 5 votes vote down vote up
/**
 * Get Activity icon
 */
public static Drawable getIcon(PackageManager pkgManager, String pkgName, String activity) {
    if (pkgManager  == null || TextUtils.isEmpty(pkgName) || TextUtils.isEmpty(activity)) {
        return null;
    }

    Intent intent = new Intent();
    intent.setClassName(pkgName, activity);
    ResolveInfo resolveInfo = pkgManager.resolveActivity(intent, 0);
    if (resolveInfo != null) {
        return resolveInfo.loadIcon(pkgManager);
    }
    return null;
}
 
Example 13
Source File: AppInfo.java    From LauncherTV with Apache License 2.0 5 votes vote down vote up
AppInfo(PackageManager packageManager, ResolveInfo resolveInfo) {
	mPackageName = resolveInfo.activityInfo.packageName;
	mIcon = resolveInfo.loadIcon(packageManager);
	try {
		mName = resolveInfo.loadLabel(packageManager).toString();
	} catch (Exception e) {
		mName = mPackageName;
	}
}
 
Example 14
Source File: IntentUtils.java    From filemanager with MIT License 5 votes vote down vote up
public static Drawable getAppIconForFile(File file, Context context)
{
	List<ResolveInfo> infos = getAppsThatHandleFile(file, context);
	PackageManager packageManager = context.getPackageManager();
	for (ResolveInfo info : infos)
	{
		Drawable drawable = info.loadIcon(packageManager);
		if (drawable != null)
			return drawable;
	}
	return null;
}
 
Example 15
Source File: ShareDialogAdapter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private Drawable loadIconForResolveInfo(ResolveInfo info) {
    try {
        final int iconRes = info.getIconResource();
        if (iconRes != 0) {
            Resources res = mManager.getResourcesForApplication(info.activityInfo.packageName);
            Drawable icon = ApiCompatibilityUtils.getDrawable(res, iconRes);
            return icon;
        }
    } catch (NameNotFoundException | NotFoundException e) {
        // Could not find the icon. loadIcon call below will return the default app icon.
    }
    return info.loadIcon(mManager);
}
 
Example 16
Source File: App.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
public App(PackageManager pm, ResolveInfo info) {
    _icon = info.loadIcon(pm);
    _label = info.loadLabel(pm).toString();
    _packageName = info.activityInfo.packageName;
    _className = info.activityInfo.name;
}
 
Example 17
Source File: SharePopup.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	// User super class to create the View
	View v = super.getView(position, convertView, parent);
	TextView tv = (TextView) v.findViewById(android.R.id.text1);

	Object handler = getItem(position);
	int iconSize = UIHelpers.dpToPx(32, getContext());
	if (handler instanceof IOrganization) {

		IOrganization org = (IOrganization) handler;
		tv.setText(org.organizationName);
		
		//todo load the org's icon from bundle or remote site
		//Drawable icon = a.getResources().getDrawable(
		//		R.drawable.ic_share_iba);
		//icon.setBounds(0, 0, iconSize, iconSize);
		//tv.setCompoundDrawables(icon, null, null, null);
		
		tv.setCompoundDrawablePadding(UIHelpers.dpToPx(10, getContext()));
	} else if (handler instanceof HandlerIntent) {
		HandlerIntent handlerIntent = (HandlerIntent) handler;
		ResolveInfo info = handlerIntent.resolveInfo;
		PackageManager pm = getContext().getPackageManager();
		tv.setText(info.loadLabel(pm));

		Drawable icon = info.loadIcon(pm);
		icon.setBounds(0, 0, iconSize, iconSize);

		// Put the image on the TextView
		tv.setCompoundDrawables(icon, null, null, null);
		tv.setCompoundDrawablePadding(UIHelpers.dpToPx(10, getContext()));
	}

	// Add margin between image and text (support various screen
	// densities)
	int dp5 = (int) (5 * a.getResources().getDisplayMetrics().density + 0.5f);
	tv.setCompoundDrawablePadding(dp5);

	return v;
}
 
Example 18
Source File: ContextualSearchQuickActionControl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void resolveIntent() {
    try {
        mIntent = Intent.parseUri(mQuickActionUri, 0);
    } catch (URISyntaxException e) {
        // If the intent cannot be parsed, there is no quick action available.
        ContextualSearchUma.logQuickActionIntentResolution(mQuickActionCategory, 0);
        reset();
        return;
    }

    PackageManager packageManager = mContext.getPackageManager();

    // If a default is set, PackageManager#resolveActivity() will return the ResolveInfo
    // for the default activity.
    ResolveInfo possibleDefaultActivity = packageManager.resolveActivity(mIntent, 0);

    // PackageManager#queryIntentActivities() will return a list of activities that can handle
    // the intent, sorted from best to worst. If there are no matching activities, an empty
    // list is returned.
    List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(
            mIntent, 0);

    int numMatchingActivities = 0;
    ResolveInfo defaultActivityResolveInfo = null;
    for (ResolveInfo resolveInfo : resolveInfoList) {
        // TODO(twellington): do not count browser activities as a match?
        if (resolveInfo.activityInfo != null && resolveInfo.activityInfo.exported) {
            numMatchingActivities++;

            // Return early if this resolveInfo matches the possibleDefaultActivity.
            ActivityInfo possibleDefaultActivityInfo = possibleDefaultActivity.activityInfo;
            if (possibleDefaultActivityInfo == null) continue;

            ActivityInfo resolveActivityInfo = resolveInfo.activityInfo;
            boolean matchesPossibleDefaultActivity =
                    TextUtils.equals(resolveActivityInfo.name,
                            possibleDefaultActivityInfo.name)
                    && TextUtils.equals(resolveActivityInfo.packageName,
                            possibleDefaultActivityInfo.packageName);

            if (matchesPossibleDefaultActivity) {
                defaultActivityResolveInfo = resolveInfo;
                break;
            }
        }
    }

    ContextualSearchUma.logQuickActionIntentResolution(mQuickActionCategory,
            numMatchingActivities);

    if (numMatchingActivities == 0) {
        reset();
        return;
    }

    mHasQuickAction = true;
    Drawable iconDrawable = null;
    int iconResId = 0;
    if (defaultActivityResolveInfo != null) {
        iconDrawable = defaultActivityResolveInfo.loadIcon(mContext.getPackageManager());

        if (mQuickActionCategory != QuickActionCategory.PHONE) {
            // Use the default app's name to construct the caption.
            mCaption = mContext.getResources().getString(
                    DEFAULT_APP_CAPTION_MAP.get(mQuickActionCategory),
                    defaultActivityResolveInfo.loadLabel(packageManager));
        } else {
            // The caption for phone numbers does not use the app's name.
            mCaption = mContext.getResources().getString(
                    DEFAULT_APP_CAPTION_MAP.get(mQuickActionCategory));
        }
    } else {
        iconResId = ICON_MAP.get(mQuickActionCategory);
        mCaption = mContext.getResources().getString(
                FALLBACK_CAPTION_MAP.get(mQuickActionCategory));
    }

    inflate();

    if (iconDrawable != null) {
        ((ImageView) getView()).setImageDrawable(iconDrawable);
    } else {
        ((ImageView) getView()).setImageResource(iconResId);
    }

    invalidate();
}
 
Example 19
Source File: IconsManager.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
IconPackInfo(ResolveInfo r, PackageManager packageManager) {
    packageName = r.activityInfo.packageName;
    icon = r.loadIcon(packageManager);
    label = r.loadLabel(packageManager);
}
 
Example 20
Source File: PackageManagerDelegate.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the icon of the app.
 * @param resolveInfo The identifying information for an app.
 * @return The icon for this app.
 */
public Drawable getAppIcon(ResolveInfo resolveInfo) {
    return resolveInfo.loadIcon(ContextUtils.getApplicationContext().getPackageManager());
}