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();
        }
    }
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.