将数字放入计算器

时间:2019-05-29 18:31:25

标签: java android

我有这段代码可以打开android的计算器(默认情况下)。 我想做的是输入数字和计算,例如: 当应用程序打开时,出现:sin(180)

我不知道我是否要解释自己

public void ac(){
    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
        Toast.makeText(CMF_Home.this, "You don't have an calculator app", Toast.LENGTH_SHORT).show();
    }

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_APP_CALCULATOR);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

0 个答案:

没有答案