视频直播系统源码,保存平台视频内容到本地

视频直播系统源码,保存平台视频内容到本地

首先,动态获取权限,非常重要

 


//在进入主页面时动态获取(记得在清单文件中添加)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{"android.permission.CAMERA",
                    "android.permission.READ_EXTERNAL_STORAGE",
                    "android.permission.WRITE_EXTERNAL_STORAGE"},101);
        }

话不多说,直接上代码

 


//在自己手机本地选择一个路径用于存储
private String path = "/sdcard/下载/Photo/";
@OnClick(R.id.fra_person_iv_photo)
    public void onViewClicked() {
        //点击打开相机
        Intent intent = new Intent();
        intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
        //设置输出路径
        path = path+getNowTime()+".jpg";
        Uri uri = FileProvider.getUriForFile(getActivity(), "com.example.android_mvp_dagger", new File(path));
        intent.putExtra(MediaStore.EXTRA_OUTPUT,uri);
        startActivityForResult(intent,102);
    }
//提供一个方法获取当前时间
    private String getNowTime() {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");
        return simpleDateFormat.format(date);
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //判断是否调用成功
        if(requestCode == 102 && resultCode == Activity.RESULT_OK) {
           //这里使用Glide进行加载图片
           GlideUtils.getInstance().CommonGlide(getActivity(),String.valueOf(path),fraPersonIvPhoto);
        }
    }

 

完成这些还是不够的,还需要在清单文件中再配置一下

 


<application
        android:name=".MyApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true"
        tools:ignore="GoogleAppIndexingWarning">
        <meta-data android:name="design_width" android:value="1080" />
        <meta-data android:name="design_height" android:value="1920" />android:name=".mvp.view.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider
        //这是一个权限,一定记得添加
            android:grantUriPermissions="true"
            //这是你项目的包路径
            android:authorities="com.example.android_mvp_dagger"
            //导入FileProvider的包路径
            android:name="androidx.core.content.FileProvider">
            //进入上面这条语句,可以获取到我们所需的下面这句话
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
            //这是一个xml文件,里面配置了我们的根路径
                android:resource="@xml/path" />
        </provider>
    </application>

 

这是上面所需的XML文件

 


<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="mypath"
        //这个一定要是SD后的那部分,不可写上SD卡
        path="下载/Photo/" />
</paths>

 

以上就是视频直播系统源码,保存平台视频内容到本地, 更多内容欢迎关注之后的文章

 

posted @ 2022-07-22 14:18  云豹科技-苏凌霄  阅读(231)  评论(0)    收藏  举报