美文网首页
Android 里面获取屏幕宽高和获取外部SD卡路径

Android 里面获取屏幕宽高和获取外部SD卡路径

作者: Raybon_lee | 来源:发表于2015-10-09 19:05 被阅读134次

    代码如下

    
    /**
     * 获取SD卡路径
     * @param menu
     * @return 
    */
    public  String getSDPathfile(){  
      File sdDirect = null;  
      boolean sdCardExit = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);  
      if (sdCardExit){  
          sdDirect  = Environment.getExternalStorageDirectory(); 
       }   
     return sdDirect.toString();
    }
    

    获取屏幕宽高和分辨率

    
    String path = getSDPathfile();
    System.out.println("我"+path);
    final PackageManager packageManager = getPackageManager();
    final Intent intent = new Intent(Intent.ACTION_MAIN,null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List<ResolveInfo> apps = packageManager.queryIntentActivities(intent,0);
    System.out.println( "我哈哈"+apps);
    //获取屏幕的宽和高
    //方法一
    WindowManager windowManager = getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    int screenWidth =display.getWidth();
    int screenHeight = display.getHeight();
    System.out.println( "我方法一"+screenWidth+"-----"+screenHeight);
    //方法二
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    float width = displayMetrics.widthPixels*displayMetrics.density;
    float height = displayMetrics.heightPixels* displayMetrics.density;
    System.out.println( "我dis "+displayMetrics.toString()+"kuan"+width+"高"+height);
    

    相关文章

      网友评论

          本文标题:Android 里面获取屏幕宽高和获取外部SD卡路径

          本文链接:https://www.haomeiwen.com/subject/upvncttx.html