Android 7.0 APK 자동 설치 및 사진 붕괴 문제

해결 방법
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 파일 의 내용 은 다음 과 같 습 니 다.
        
        <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();
        }
    }

좋은 웹페이지 즐겨찾기