How to call android calculator on my app for all phones

前端 未结 4 1630
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 02:17
  public static final String CALCULATOR_PACKAGE =\"com.android.calculator2\";
  public static final String CALCULATOR_CLASS =\"com.android.calculator2.Calculator\";
         


        
4条回答
  •  不知归路
    2020-12-03 02:32

    You'll have to check if the default calculator package name(com.android.calculator2) is available with this:

    try{
         ApplicationInfo info = getPackageManager()
                                 .getApplicationInfo("com.android.calculator2", 0 );
    
        } catch( PackageManager.NameNotFoundException e ){
         //application doesn't exist
    }
    

    Samsung uses a lot of apps preinstalled with TouchWiz which aren't available in stock Android. Therefore if you get an Exception in the above you can check if Samsung's calculator is available. Btw I think com.android.calculator2 is not HTC specific.

提交回复
热议问题