react-native-send-intent icon indicating copy to clipboard operation
react-native-send-intent copied to clipboard

fix: openFilePicker bug

Open 1uokun opened this issue 4 years ago • 1 comments

Usage

Basic usage

SendIntent.openFilePicker({
    type:"*/*",
    title:"Choose file",
    multiple:false
},(e)=>{
    console.log(JSON.parse(e))
});

Picker the specified type file, eg:".PDF"

SendIntent.openFilePicker({type:"application/pdf"},(e)=>{
   console.log(JSON.parse(e))
});

Multiple File Picker

SendIntent.openFilePicker({multiple:true},(e)=>{
   console.log(JSON.parse(e))
});

Permission

need READ_EXTERNAL_STORAGE

const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
    {
        title: '"need READ_EXTERNAL_STORAGE permission",
        message:
                  'If not allowed, you will not be able to picker someone file',
        buttonNeutral: 'Later',
        buttonNegative: 'Cancel',
        buttonPositive: 'OK',
    },
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    SendIntent.openFilePicker({},(e)=>{
        // check returns is a real path
        FetchBlob.fs.stat(JSON.parse(e)[0]).then(res=>{
            console.log(res)
        }).catch(err=>{
            console.log(err)
        })
    });
}

1uokun avatar Sep 01 '20 04:09 1uokun

optimization form https://github.com/lucasferreira/react-native-send-intent/pull/95

1uokun avatar Sep 01 '20 04:09 1uokun