마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

API22레벨에서 API 26레벨로 업데이트 후 Activity.java 파일에서 Import 오류 발생합니다.

0 추천

1.API22=>API26 으로 업데이트 이후 앱에서 사진불러오기를 하는데 오류가 발생합니다.

Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/tmp_1543123435953.jpg exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9510)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9468)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
at android.app.Activity.startActivityForResult(Activity.java:4389)
at android.app.Activity.startActivityForResult(Activity.java:4348)
at com.xxxxx.xxxxxx.activity.join.Join2Activity.onActivityResult(Join2Activity.java:393)
at android.app.Activity.dispatchActivityResult(Activity.java:7226)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4443)

2.오류가 발생하는 소스 부분입니다. 

startActivityForResult(intent, CROP_FROM_CAMERA); <= 여기서 오류 발생

case PICK_FROM_CAMERA:
            {
                // 이미지를 가져온 이후의 리사이즈할 이미지 크기를 결정합니다.
                // 이후에 이미지 크롭 어플리케이션을 호출하게 됩니다.

                Intent intent = new     Intent("com.android.camera.action.CROP");
                intent.setDataAndType(mImageCaptureUri, "image/*");
                intent.putExtra("outputX", 500);
                intent.putExtra("outputY", 500);
// 크롭 비율
                intent.putExtra("aspectX", 0);
                intent.putExtra("aspectY", 0);
                intent.putExtra("scale", true);
                // Crop한 이미지를 저장할 Path
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri); // 임시파일 생성
                intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());

                startActivityForResult(intent, CROP_FROM_CAMERA);
                break;
            }

 

3.그래서 찾아가보니  \SDK\sources\android-26\android\app\Activity.java파일 안에 아래 import 들이 모두 빨간색 오류 표시가 납니다..

import android.annotation.CallSuper;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.LayoutRes;
import android.annotation.MainThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.StyleRes;
import android.annotation.SystemApi;
import android.content.IIntentSender;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.SystemProperties;
import android.util.Slog;
import android.util.SuperNotCalledException;
import android.view.ViewRootImpl;
import android.view.ViewRootImpl.ActivityConfigCallback;
import android.view.Window.WindowControllerCallback;
import android.view.WindowManagerGlobal;
import android.view.autofill.AutofillPopupWindow;
import android.view.autofill.IAutofillWindowPresenter;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.ToolbarActionBar;
import com.android.internal.app.WindowDecorActionBar;
import com.android.internal.policy.DecorView;
import com.android.internal.policy.PhoneWindow;

2.Project - build gradle 내용

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        //classpath 'com.google.gms:google-services:4.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

 

3.app - build gradle내용

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.xxxx.xxxxx"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 34
        versionName "1.33"

    }
    signingConfigs {
        release {
            storeFile file("xxxxxxx")
            storePassword "xxxx"
            keyAlias "xxxxx"
            keyPassword "xxxxx"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
}

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:22.0.1'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.android.gms:play-services:8.3.0'
    implementation files('libs/glide-3.6.1.jar')
    implementation files('libs/jsoup-1.8.3.jar')

}

##왜 이런 오류가 발생하는거죠?아무리 찾아봐도 알수가 없네요 초보자에겐 너무 어렵습니다.

    제가 뭘 잘못 한건지 고수님들 한수 부탁 드리겠습니다.~

왕초보자 (120 포인트) 님이 2018년 11월 25일 질문

1개의 답변

0 추천
import는 상관없고,  target_sdk 올리면서 적용되는 Android 7.0 보안관련 변경사항입니다.

다음 링크에 "파일 시스템 권한 변경" 항목을 살펴 보세요.

https://developer.android.com/about/versions/nougat/android-7.0-changes?hl=ko
디자이너정 (42,810 포인트) 님이 2018년 11월 25일 답변
감사합니다..권한 문제였군요
Activity.java파일안에 import 빨갛게 오류뜨는건 신경 안쓰도 돼는겁니까?
...