This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| package="com.chayangkoon.champ.scopedstorage"> | |
| <!--สำหรับการอ่านไฟล์ต่างๆใน External Storage บนอุปกรณ์--> | |
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |
| <!--สำหรับการเขียนไฟล์ต่างๆใน External Storage บนอุปกรณ์--> | |
| <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" | |
| android:maxSdkVersion="28"/> | |
| ... | |
| </manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val externalStorageVolumes: Array<out File> = ContextCompat.getExternalFilesDirs(applicationContext, null) | |
| val primaryExternalStorage = externalStorageVolumes[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ตรวจสอบ External storage ว่าพร้อมใช้งานทั้งอ่านและเขียนไฟล์หรืิอไม่ | |
| fun isExternalStorageWritable(): Boolean { | |
| return Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED | |
| } | |
| // ตรวจสอบ External storage ว่าพร้อมใช้งานสำหรับการอ่านไฟล์หรือไม่ | |
| fun isExternalStorageReadable(): Boolean { | |
| return Environment.getExternalStorageState() in | |
| setOf(Environment.MEDIA_MOUNTED, Environment.MEDIA_MOUNTED_READ_ONLY) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ถ้าไม่ใช้ SAM Conversions จะเขียน Code ประมาณนี้ | |
| adapter.setOnItemClickListener(object : OnItemClickListener { | |
| override fun onItemClick(position: Int) { | |
| // handle onItemClick | |
| } | |
| }) | |
| // แต่ถ้าใช้ SAM Conversions จะเขียนในรูปแบบของ Lambda Expression | |
| adapter.setOnItemClickListener { | |
| // handle onItemClick |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun interface OnItemClickListener { | |
| fun onItemClick(position: Int) | |
| } | |
| fun setOnItemClickListener(onItemClickListener: OnItemClickListener){ | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ถ้าไม่ใช้ SAM Conversions จะเขียน Code ประมาณนี้ | |
| view.setOnClickListener(object : View.OnClickListener { | |
| override fun onClick(view: View?) { | |
| // handle onClick | |
| } | |
| }) | |
| // แต่ถ้าใช้ SAM Conversions จะเขียนในรูปแบบของ Lambda Expression | |
| view.setOnClickListener { | |
| // handle onClick |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface OnClickListener { | |
| void onClick(View view); | |
| } | |
| public void setOnClickListener(@Nullable View.OnClickListener l) { | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun getAppSpecificAlbumStorageDir(context: Context, albumName: String): File? { | |
| val file = File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), albumName) | |
| if (!file.mkdirs()) { | |
| Log.e(LOG_TAG, "Directory not created") | |
| } | |
| return file | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| package="com.chayangkoon.champ.scopedstorage"> | |
| <application | |
| ... | |
| android:requestLegacyExternalStorage="true"> | |
| ... | |
| </application> | |
| </manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| package="com.chayangkoon.champ.scopedstorage"> | |
| <!--สำหรับการอ่านไฟล์ต่างๆใน External Storage บนอุปกรณ์--> | |
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | |
| <!--สำหรับการเขียนไฟล์ต่างๆใน External Storage บนอุปกรณ์--> | |
| <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
| ... | |
| </manifest> |
NewerOlder