public static final String CALCULATOR_PACKAGE ="com.android.calculator2"; public static final String CALCULATOR_CLASS ="com.android.calculator2.Calculator"; Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName( CALCULATOR_PACKAGE,CALCULATOR_CLASS));
以上仅适用于HTC
public static final String CALCULATOR_PACKAGE ="com.sec.android.app.popupcalculator"; public static final String CALCULATOR_CLASS ="com.sec.android.app.popupcalculator.Calculator";
以上作品为S3
解决方法
您可以尝试所有Android设备上的默认计算器:
ArrayList<HashMap<String,Object>> items =new ArrayList<HashMap<String,Object>>(); final PackageManager pm = getPackageManager(); List<PackageInfo> packs = pm.getInstalledPackages(0); for (PackageInfo pi : packs) { if( pi.packageName.toString().toLowerCase().contains("calcul")){ HashMap<String,Object> map = new HashMap<String,Object>(); map.put("appName",pi.applicationInfo.loadLabel(pm)); map.put("packageName",pi.packageName); items.add(map); } }
现在您可以启动计算器应用程序:
if(items.size()>=1){ String packageName = (String) items.get(0).get("packageName"); Intent i = pm.getLaunchIntentForPackage(packageName); if (i != null) startActivity(i); } else{ // Application not found }
而对于Api> = 15,您可以使用
Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_APP_CALCULATOR); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);