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

代码如下


/**
 * 获取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 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卡路径)