๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - ์นด๋ฉ”๋ผ/ ์•จ๋ฒ” ์ฒ˜๋ฆฌ ์„ค์ • ๋ฐฉ๋ฒ• ๋ณธ๋ฌธ

๐Ÿค–Android

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - ์นด๋ฉ”๋ผ/ ์•จ๋ฒ” ์ฒ˜๋ฆฌ ์„ค์ • ๋ฐฉ๋ฒ•

๋ฃจ๋ฆฌ์•ผใ…‘ 2024. 1. 10. 18:03
๋ฐ˜์‘ํ˜•

์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ ๊ฐœ๋ฐœ ์‹œ ์นด๋ฉ”๋ผ์™€ ์•จ๋ฒ” ์ฒ˜๋ฆฌ์˜ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์ž.

 

1. AndroidManifest.xml

๋งจ ์œ„์—์„œ ์ธํ„ฐ๋„ท ๊ถŒํ•œ์„ค์ •๊ณผ permission ์„ค์ •์„ ํ•ด์ค€๋‹ค.

<uses-feature
        android:name="android.hardware.camera"
        android:required="true" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA"/>

android:authorities="com.sunny.cameraapp๋ณธ์ธ ํŒจํ‚ค์ง€๋ช….fileprovider" ์—์„œ
๋ณธ์ธ ํŒจํ‚ค์ง€ ๋งค๋ฒˆ ๋ฐ”๊ฟ”์•ผ ํ•œ๋‹ค

<application

	...

    <provider
        android:authorities="com.sunny.cameraapp.fileprovider"
        android:name="androidx.core.content.FileProvider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/fileprovider"/>
    </provider>
    
    ...

</application>

 

2.xml - fileprovider.xml ๋ฆฌ์†Œ์Šค ํŒŒ์ผ ์ƒ์„ฑ

์žฌํ™œ์šฉ ์ฝ”๋“œ์ด๋ฏ€๋กœ ํŒŒ์ผ ํ†ต์งธ๋กœ ๋ถ™์—ฌ ๋„ฃ๋Š”๋‹ค.

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <root-path
        name="root"
        path="." />

    <cache-path
        name="cache"
        path="." /> <!--Context.getCacheDir() ๋‚ด๋ถ€ ์ €์žฅ์†Œ-->
    <files-path
        name="files"
        path="." /> <!--Context.getFilesDir() ๋‚ด๋ถ€ ์ €์žฅ์†Œ-->

    <external-path
        name="external"
        path="."/>  <!--  Environment.getExternalStorageDirectory() ์™ธ๋ถ€ ์ €์žฅ์†Œ-->
    <external-cache-path
        name="external-cache"
        path="."/> <!--  Context.getExternalCacheDir() ์™ธ๋ถ€ ์ €์žฅ์†Œ-->
    <external-files-path
        name="images"
        path="Pictures" /> <!--  Context.getExternalFilesDir() ์™ธ๋ถ€ ์ €์žฅ์†Œ-->
</paths>

 

 

3. buil.gradle.kts ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์ •

dependencies {

    implementation("commons-io:commons-io:2.4")
    
    // ์‚ฌ์ง„๊ฐ€์ ธ์˜ค๋Š” Glide ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
    implementation ("com.github.bumptech.glide:glide:4.16.0")
}
๋ฐ˜์‘ํ˜•