Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Android calculator on my app for all phones

  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));

the above works for HTC only

  public static final String CALCULATOR_PACKAGE ="com.sec.android.app.popupcalculator";
  public static final String CALCULATOR_CLASS ="com.sec.android.app.popupcalculator.Calculator";

the above works for S3

I need a code that works for all of them. Someone with any clue ?Please give an example code

like image 825
Simon Macha Mwas Avatar asked Dec 01 '12 18:12

Simon Macha Mwas


People also ask

How do I get my calculator to work on my Android phone?

To access the Calculator, swipe up on a Home screen to open the Apps screen, and then navigate to and tap Calculator.

How do I add calculator to Quick Settings Android?

Swipe down twice from the top of your screen to open your full Quick Settings panel. Tap the pencil-shaped icon at the bottom of that panel, then scroll all the way to the bottom of the list to find the "Floating Calculator" button down in the inactive tiles section.

Does Android have a built in calculator?

You can do simple or advanced calculations with your phone's Calculator app . Important: You can use the Calculator app on Android 6.0 and up. Get the Calculator app on the Google Play Store.


2 Answers

you can try as to Default calculator on all android devices:

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);
 }
}

and now you can launch calculator application as:

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
   }

And for Api >= 15 ,You can use

Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_CALCULATOR);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
like image 81
ρяσѕρєя K Avatar answered Sep 28 '22 05:09

ρяσѕρєя K


Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_APP_CALCULATOR);
startActivity(i);
like image 25
Igor Avatar answered Sep 28 '22 05:09

Igor