0

sorry for my bad english

i have tried so much to create a directory in data/data/pkg/ or sdcard/storage/0/Android/data/pkg/

in Kotlin

i tried :

Android - Creating a folder in the data/data/pkg/files directory

https://www.tabnine.com/code/java/methods/android.content.Context/getExternalFilesDir

https://www.tabnine.com/code/java/methods/android.content.Context/getFilesDir

/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/

i have these permissions in my manifest:

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
changer
  • 1
  • 1

1 Answers1

0

You can do something like this:

String fileName = "FILE_NAME";
String filePath = context.getExternalFilesDir("FOLDER_NAME").toString()+"/"+fileName;
FileOutputStream fileOutputStream = new FileOutputStream(filePath);

Example: Save Bitmap in internal storage

public static void downloadToInternalStorage(Context context, Bitmap bitmap) throws IOException {
    String fileName = "image.jpg";
    String filePath = context.getExternalFilesDir("images").toString()+"/"+fileName;

    FileOutputStream fileOutputStream = new FileOutputStream(filePath);
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
    fileOutputStream.flush();
    fileOutputStream.close();
}

In Kotlin

@kotlin.jvm.Throws(IOException::class)
fun downloadToInternalStorage(context: Context?, bitmap: Bitmap) {
    val fileName = "image.jpg"
    val filePath: String = context.getExternalFilesDir("images").toString().toString() + "/" + fileName
    val fileOutputStream = FileOutputStream(filePath)
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)
    fileOutputStream.flush()
    fileOutputStream.close()
}
Muhammad Shuja
  • 642
  • 5
  • 18