解决方法

1,在AndroidManifest中添加

       <provider            android:name="android.support.v4.content.FileProvider"            android:authorities="${applicationId}.fileProvider"            android:grantUriPermissions="true"            android:exported="false">            <meta-data                android:name="android.support.FILE_PROVIDER_PATHS"                android:resource="@xml/file_paths" />        provider>

2,在res目录下新建xml文件夹,添加file_paths.xml文件,内容如下:

        <?xml version="1.0" encoding="utf-8"?>        <paths>            <external-path path="Android/data/com.heyikun.hehemall/" name="files_root" />            <external-path path="." name="external_storage_root" />            <external-path name="external_storage_root" path="."/>            <files-path name="files" path="."/>        paths>

3,安装APP

    private void installApk(File file) {        Intent install = new Intent(Intent.ACTION_VIEW);        //判断是否是AndroidN以及更高的版本        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {            install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);            Uri contentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileProvider", file);            install.setDataAndType(contentUri, "application/vnd.android.package-archive");        } else {            install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");            install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        }        mContext.startActivity(install);    }

4,拍照

  public Intent dispatchTakePictureIntent() throws IOException {    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {      File file = createImageFile();      Uri photoFile;      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {        String authority = mContext.getApplicationInfo().packageName + ".fileProvider";        photoFile = FileProvider.getUriForFile(this.mContext.getApplicationContext(), authority, file);      } else {        photoFile = Uri.fromFile(file);      }      if (photoFile != null) {        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);      }    }    return takePictureIntent;  }    private void openCamera() {        try {            Intent intent = captureManager.dispatchTakePictureIntent();            startActivityForResult(intent, ImageCaptureManager.REQUEST_TAKE_PHOTO);        } catch (IOException e) {            e.printStackTrace();        } catch (ActivityNotFoundException e) {            // TODO No Activity Found to handle Intent            e.printStackTrace();        }    }

更多相关文章

  1. Android中实现下载和解压zip文件功能代码分享
  2. Android的ListView中判断其内容已滚动到最顶部或者最底部
  3. Android文件解压工具类
  4. android apk dex odex jar 等文件的 反编译工具
  5. 【转】android编译系统的makefile文件Android.mk写法
  6. Android+JNI调用–文件操作
  7. Android错误处理——Android读取txt文件乱码解决方案
  8. Android 10 创建文件失败
  9. cvc-complex-type.2.4.d: 发现了以元素 'd:skin' 开头的无效内容

随机推荐

  1. Android(安卓)ADB超简单的安装方法
  2. android 界面布局 很好的一篇总结
  3. 通过ua检测浏览页面的设备是phone还是tab
  4. Android中数据存储的5中方法
  5. Android入门讲解(一)
  6. 网络请求框架(Volley)
  7. Android缺少awk:安装busybox
  8. Android(安卓)开发之多线程处理、Handler
  9. Android(安卓)Studio NDK开发案例一 JNI
  10. Android FileObserver 用法