天天看點

擷取SD卡 tf卡 内置外置存儲卡路徑名稱 路徑的方式

擷取SD卡 tf卡 内置外置存儲卡路徑名稱 路徑的方式  

直接附上 例子 

http://download.csdn.net/detail/v587ge/8594391

還有一種讀取外置TF的方法 

public String GetSDcardPath(Context context) {
		String mPath = null;
		if (mSDCardPath.length() == 0) {
			Method mMethodGetPaths = null;
			String[] strs = null;
			StorageManager mStorageManager;
			mStorageManager = (StorageManager) context.getSystemService(Activity.STORAGE_SERVICE);
			try {
				mMethodGetPaths = mStorageManager.getClass().getMethod("getVolumePaths");
			} catch (NoSuchMethodException e) {
				e.printStackTrace();
			}
			try {
				strs = (String[]) mMethodGetPaths.invoke(mStorageManager);
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}


			if (strs[0].equals(Environment.MEDIA_MOUNTED)) {
				mPath = strs[0];
				Log.e("tag", "第0個有外部存儲卡" + strs[0]);
			} else {
				mPath = strs[1];
				Log.e("tag", "第1個有外部存儲卡" + strs[1]);
			}
			if (mPath != null) {
				mPath = mPath + "/xiaoerlang/tongBuDianDu/";
				mSDCardPath = mPath;
				File f = new File(mPath);
				if (f.exists()) {
				} else {
					f.mkdirs();
				}
			} else {
				return null;
			}
		}


		return mSDCardPath;


	}
           

這種方法讀取就非常的慢 很耗時