Code Monkey home page Code Monkey logo

android-resource-file-provider's Introduction

Android Resource File Provider

API license Android Arsenal Build Status

Easily share audio, video, image and document files from raw, assets and drawable folders without any specific permission.

Installation

Include the dependency in your app build.gradle file:

implementation 'it.federicoboschini:resource-file-provider:1.0.0'

If you are experiencing any issue with resource merging or support-library compatibility add the dependency excluding com.android.support:

implementation('it.federicoboschini:resource-file-provider:1.0.0') {
    exclude group: 'com.android.support'
}

Configuration

Add this to your app AndroidManifest.xml:

<application>
<!--    ...     -->
    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="@string/rfp_provider_authority"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_provider_paths" />
    </provider>
<!--    ...     -->
</application>

Optional Add this (provider authority) to your app strings.xml:

<resources>
    <!--    ...     -->
    <string name="rfp_provider_authority">it.my_company.my_app.my_authority</string>
    <!--    ...     -->
</resources>

Optional Define custom file paths by creating a file_provider_paths in res/xml:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <!-- Define the desired file paths -->
    
    <!--    The default is:     -->
    <!-- <files-path name="all" path="/"/> -->
</paths>

Example: share a mp3 file

try {
    ResourceFileProvider.Builder
        .from(this)
        .setDirectory(FOLDER_RAW)
        .setFileName("my_sound")
        .setFileExtension("mp3")
        .setFileType(TYPE_AUDIO)
        .build()
        .shareFile();
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

Note: setFileName parameter is without the extension.

Current supported and tested extensions:

  • .mp3
  • .jpg
  • .png
  • .pdf
  • .mp4

Current supported and tested folders:

  • drawable
  • raw
  • assets

Note: if your project contains density-dependent drawables, the nearest to the device density will be selected.

Known issues:

  • Can't get images from mipmap folder.

android-resource-file-provider's People

Contributors

federicoboschini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

android-resource-file-provider's Issues

Cannot resolve import

Android Studio Version: Android Studio Chipmunk | 2021.2.1 Patch 1
Gradle Version: 7.3.3
Compile SDK: 32
MinSDK: 21
TargetSDK: 32

Code:

import it.federicoboschini.resourcefileprovider.ResourceFileProvider;

Error:

Cannot resolve 'federicoboschini'

build.gradle:

implementation 'it.federicoboschini:resource-file-provider:1.0.0'

also tested with:

implementation('it.federicoboschini:resource-file-provider:1.0.0') {
    exclude group: 'com.android.support'
}

.from(this)

error: incompatible types: cannot be converted to Activity
.from(this)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.