问题描述
感谢上次回复,
是否可以获取安装在设备上的摄像机应用程序的包名称?如果操作系统是自定义的,则设备制造商更改了默认包名称.如何通过编码获取包名称?我不确定这是可能的.
推荐答案
我不确定,但我认为你可以使用指定的意图 ..
查看此代码以获取处理特定意图的可用应用程序信息
/** * 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 list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }现在使用 camera意图您可以获得处理IMAGE_CAPTURE意图并使用您可以轻松获取包名称的信息的应用程序信息.
更新:
在您的情况下,特定的意图是
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
编辑:
List<ResolveInfo> listCam = packageManager.queryIntentActivities(intent, 0); for (ResolveInfo res : listCam) { Log.e("Camera Application Package Name and Activity Name",res.activityInfo.packageName + " " + res.activityInfo.name)); }
试试这个,让我知道发生了什么..
其他推荐答案
你试过这个吗?
PackageManager packman = getPackageManager(); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String pack = intent.resolveActivity(packman).getPackageName();
其他推荐答案
请参阅 http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-con
class PInfo { private String appname = ""; private String pname = ""; private String versionName = ""; private int versionCode = 0; private Drawable icon; private void prettyPrint() { Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode); } } private ArrayList<PInfo> getPackages() { ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */ final int max = apps.size(); for (int i=0; i<max; i++) { apps.get(i).prettyPrint(); } return apps; } private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) { ArrayList<PInfo> res = new ArrayList<PInfo>(); List<PackageInfo> packs = getPackageManager().getInstalledPackages(0); for(int i=0;i<packs.size();i++) { PackageInfo p = packs.get(i); if ((!getSysPackages) && (p.versionName == null)) { continue ; } PInfo newInfo = new PInfo(); newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString(); newInfo.pname = p.packageName; newInfo.versionName = p.versionName; newInfo.versionCode = p.versionCode; newInfo.icon = p.applicationInfo.loadIcon(getPackageManager()); res.add(newInfo); } return res; }
问题描述
Thanks for previous replies,
Is it possible to get Package name of camera application which is installed on the device? If the OS is customized the default package name is changed by the device manufacturer. How can I get the package name through coding ? I am not sure this will be possible.
推荐答案
I am not sure, but I think you can get package name of application using specified intent..
Look at this code for getting available application information which handle the specific intent,
/** * 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 list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
Now using Camera intent you can get the application information which handles the IMAGE_CAPTURE intent and using that information you can easily get package name.
Update:
In your case the specific intent is
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
EDIT:
List<ResolveInfo> listCam = packageManager.queryIntentActivities(intent, 0); for (ResolveInfo res : listCam) { Log.e("Camera Application Package Name and Activity Name",res.activityInfo.packageName + " " + res.activityInfo.name)); }
Try this and let me know what happen..
其他推荐答案
Did you try this?
PackageManager packman = getPackageManager(); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); String pack = intent.resolveActivity(packman).getPackageName();
其他推荐答案
see http://www.androidsnippets.com/get-installed-applications-with-name-package-name-version-and-icon
class PInfo { private String appname = ""; private String pname = ""; private String versionName = ""; private int versionCode = 0; private Drawable icon; private void prettyPrint() { Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode); } } private ArrayList<PInfo> getPackages() { ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */ final int max = apps.size(); for (int i=0; i<max; i++) { apps.get(i).prettyPrint(); } return apps; } private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) { ArrayList<PInfo> res = new ArrayList<PInfo>(); List<PackageInfo> packs = getPackageManager().getInstalledPackages(0); for(int i=0;i<packs.size();i++) { PackageInfo p = packs.get(i); if ((!getSysPackages) && (p.versionName == null)) { continue ; } PInfo newInfo = new PInfo(); newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString(); newInfo.pname = p.packageName; newInfo.versionName = p.versionName; newInfo.versionCode = p.versionCode; newInfo.icon = p.applicationInfo.loadIcon(getPackageManager()); res.add(newInfo); } return res; }