更新记录

1.0.0(2020-07-17)

        // #ifndef H5
        var x = document.createElement('input');
        x.setAttribute('type', 'file');
        x.click();
        x. = function() {
            console.log(this.files[0]);
        };
        // #endif
                  // #ifdef APP-PLUS
        var REQUESTCODE = 1;
        var main = plus.android.runtimeMainActivity();
        var Intent = plus.android.importClass('android.content.Intent');
        var intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType('*/*'); //设置类型,任意类型
        //intent.setType("image/*");
        //intent.setType("audio/*"); //选择音频
        //intent.setType("video/*"); //选择视频 (mp4 3gp 是android支持的视频格式)

        intent.addCategory(Intent.CATEGORY_OPENABLE);
        main.startActivityForResult(intent, REQUESTCODE);

        main.onActivityResult = function(requestCode, resultCode, data) {
            if (REQUESTCODE == requestCode) {
                var context = main;
                plus.android.importClass(data);
                // 获得文件路径
                var fileData = data.getData();
                var path = plus.android.invoke(fileData, 'getPath');
                console.log('path:' + path);

                // 判断文件类型
                var resolver = context.getContentResolver();
                var fileType = plus.android.invoke(resolver, 'getType', fileData);
                console.log('fileType:' + fileType);
            }
        };
        // #endif

平台兼容性

<template>
    <view class="content"><button type="default" @tap="uploadFilesFun">上传文件</button></view>
</template>

<script>
export default {
    data() {
        return {
            title: 'Hello'
        };
    },
    onLoad() {},
    methods: {
        uploadFilesFun() {
            // #ifdef APP-PLUS
            var REQUESTCODE = 1;
            var main = plus.android.runtimeMainActivity();
            var Intent = plus.android.importClass('android.content.Intent');
            var intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType('*/*'); //设置类型,任意类型
            //intent.setType("image/*");
            //intent.setType("audio/*"); //选择音频
            //intent.setType("video/*"); //选择视频 (mp4 3gp 是android支持的视频格式)

            intent.addCategory(Intent.CATEGORY_OPENABLE);
            main.startActivityForResult(intent, REQUESTCODE);

            main.onActivityResult = function(requestCode, resultCode, data) {
                if (REQUESTCODE == requestCode) {
                    var context = main;
                    plus.android.importClass(data);
                    // 获得文件路径
                    var fileData = data.getData();
                    var path = plus.android.invoke(fileData, 'getPath');
                    console.log('path:' + path);

                    // 判断文件类型
                    var resolver = context.getContentResolver();
                    var fileType = plus.android.invoke(resolver, 'getType', fileData);
                    console.log('fileType:' + fileType);
                }
            };
            // #endif

            // #ifdef H5
            var x = document.createElement('input');
            x.setAttribute('type', 'file');
            x.click();
            x. = function() {
                console.log(this.files[0]);
            };
            // #endif
        }
    }
};
</script>

<style>
.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.logo {
    height: 200rpx;
    width: 200rpx;
    margin-top: 200rpx;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 50rpx;
}

.text-area {
    display: flex;
    justify-content: center;
}

.title {
    font-size: 36rpx;
    color: #8f8f94;
}
</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问