Share image without WRITE_EXTERNAL_STORAGE?

后端 未结 1 1863
忘掉有多难
忘掉有多难 2021-01-18 12:25

Is there a way to use Intent.ACTION_SEND to share a screenshot without requiring android.permission.WRITE_EXTERNAL_STORAGE?

Here\'s the sha

相关标签:
1条回答
  • 2021-01-18 12:58

    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;
    
    public class LegacyCompatFileProvider extends FileProvider {
      @Override
      public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        return(new LegacyCompatCursorWrapper(super.query(uri, projection, selection, selectionArgs, sortOrder)));
      }
    }
    

    All this does is wrap the FileProvider query() 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.

    0 讨论(0)
提交回复
热议问题