应用的存储权限问题

内部存储(即用户不能访问的空间,外部存储指存储可能是可移除的存储介质(例如 SD 卡)或内部(不可移除)存储,详情看下面链接)

在manifest声明了shareUserId = "android.uid.system"的是不用申请外部存储permission的,但是不可以写SD卡,只能读,可以写自带(不可移除)的存储空间.

一般的应用需要读写外部存储器的话需要动态使用permission,这是从android M开始的.

mImageFilePath可以是外部存储器的路径

mImageFilePath = new File(mScreenshotDir, mImageFileName).getAbsolutePath();
		// Create the large notification icon
		mImageWidth = longscreenshotbitmap.getWidth();
		mImageHeight = longscreenshotbitmap.getHeight();
		 long dateSeconds = mImageTime / 1000;
		ContentValues values = new ContentValues();
		ContentResolver resolver = mContext.getContentResolver();
		values.put(MediaStore.Images.ImageColumns.DATA, mImageFilePath);//
		values.put(MediaStore.Images.ImageColumns.TITLE, mImageFileName);//
		values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, mImageFileName);//
		values.put(MediaStore.Images.ImageColumns.DATE_TAKEN, mImageTime);
		values.put(MediaStore.Images.ImageColumns.DATE_MODIFIED, dateSeconds);
		values.put(MediaStore.Images.ImageColumns.DATE_ADDED, dateSeconds);
		values.put(MediaStore.Images.ImageColumns.MIME_TYPE, "image/png");
		values.put(MediaStore.Images.ImageColumns.WIDTH, mImageWidth);
		values.put(MediaStore.Images.ImageColumns.HEIGHT, mImageHeight);
		Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
		if (uri == null) {
			sendMyMessage(mHandler, MESSAGE_FAIL_TO_SAVE_PIC);
			return;
		}else {
			Tools.log(TAG, "          uri != null");
		}
		try {
		    resolver.update(uri, values, null, null);
			OutputStream out = resolver.openOutputStream(uri);
			if(out == null){
				sendMyMessage(mHandler, MESSAGE_FAIL_TO_SAVE_PIC);
				return;
			}
			boolean bCompressOK = longscreenshotbitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
			Tools.log(TAG, " bCompressOK  ==" +bCompressOK);
			out.flush();
			out.close();
            // update file size in the database
            values.clear();
            values.put(MediaStore.Images.ImageColumns.SIZE, new File(mImageFilePath).length());
            int updateFileSizeResult = resolver.update(uri, values, null, null);



https://developer.android.com/guide/topics/data/data-storage.html#filesInternal

你可能感兴趣的:(移动开发综合,模块相关)