Skip to content Skip to sidebar Skip to footer

Share Image Without Write_external_storage?

Is there a way to use Intent.ACTION_SEND to share a screenshot without requiring android.permission.WRITE_EXTERNAL_STORAGE? Here's the share part: Intent shareIntent = new Inte

Solution 1:

Based on work by Stefan Rusek, I created LegacyCompatCursorWrapper, designed to help improve compatibility of FileProvider (and other ContentProvider implementations) with client apps that are looking for _DATA columns and not finding them. The _DATA pattern was used originally by MediaStore, but it was never a good idea for apps to try referring to that column.

To use it in conjunction with FileProvider, add my CWAC-Provider library as a dependency, and then create your own subclass of FileProvider, such as this one:

/***
 Copyright (c) 2015 CommonsWare, LLC
 Licensed under the Apache License, Version 2.0 (the "License"); you may not
 use this file except in compliance with the License. You may obtain a copy
 of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
 by applicable law or agreed to in writing, software distributed under the
 License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 OF ANY KIND, either express or implied. See the License for the specific
 language governing permissions and limitations under the License.

 From _The Busy Coder's Guide to Android Development_
 http://commonsware.com/Android
 */

package com.commonsware.android.cp.v4file;

import android.database.Cursor;
import android.net.Uri;
import android.support.v4.content.FileProvider;
import com.commonsware.cwac.provider.LegacyCompatCursorWrapper;

publicclassLegacyCompatFileProviderextendsFileProvider {
  @OverridepublicCursorquery(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    return(newLegacyCompatCursorWrapper(super.query(uri, projection, selection, selectionArgs, sortOrder)));
  }
}

All this does is wrap the FileProviderquery() results in a LegacyCompatCursorWrapper. The rest of your app configuration would be identical to using FileProvider directly (e.g., <meta-data> element), except that your <activity> element's android:name attribute would point to your own class. You can see this in action in this sample app.

Post a Comment for "Share Image Without Write_external_storage?"