开机时判断是否有U盘插入

	private static String VIDEO_NAME = "egreat.mp4";
	private static String BASE_PATH = "/mnt/usb/";
	private static String VIDEO_PATH_1 = "/mnt/usb/sda4/egreat.mp4";
	private static String VIDEO_PATH_2 = "/mnt/usb/sda4/egreat.mp4";

	/**
	 * 检测USB 状态
	 */
	private void checkUsb() {
		/* 判断是否有U盘插入 */
		File sdDir1 = new File("/mnt/usb/");
		String[] videoPath;
		Log.d(TAG, "custom file path" + sdDir1);
		if (sdDir1.exists() && sdDir1.isDirectory()) {
			videoPath = sdDir1.list();
			if (sdDir1.list().length == 1) {
				Log.d(TAG, "U disk exist one ");
				VIDEO_PATH_1 = BASE_PATH+videoPath[0]+"/"+VIDEO_NAME;
				mMainActivityHolder.getmUsbStateTextView().setText(R.string.usb_ok_one);
			} else if (sdDir1.list().length == 2) {
				Log.d(TAG, "U disk exist two ");
				VIDEO_PATH_1 = BASE_PATH+videoPath[0]+"/"+VIDEO_NAME;
				VIDEO_PATH_2 = BASE_PATH+videoPath[1]+"/"+VIDEO_NAME;
				mMainActivityHolder.getmUsbStateTextView().setText(R.string.usb_ok_two);
			} else {
				Log.d(TAG, "U disk not exist");
				mMainActivityHolder.getmUsbStateTextView().setText(R.string.usb_fail);
			}
			Log.d(TAG, "================"+VIDEO_PATH_1);
			Log.d(TAG, "================"+VIDEO_PATH_2);
		}
	}







阅读更多
文章标签: u盘 Android 检测
个人分类: android零碎知识点
上一篇隐藏应用,在应用列表里不显示
下一篇android.os.NetworkOnMainThreadException 异常处理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭