1 year ago

#363646

test-img

Muhammad Hamza Ishtiaq

Getting file from external storage after re-Install app

Here I am using this code for saving file to external storage and also get that file after Re Install application

I am testing it on Android 12 and also help me about the access restrictions in Android after OS 10

public static String read_file_from_external_storage(Context mContext, String FileName) {
    
            // start main . sa android od is folder ko hidden kr data hai
    
            String FileData = "";
            int ch = 0;
            StringBuffer strContent = new StringBuffer("");
    
            try {
    
                java.io.File root = new java.io.File(android.os.Environment.getExternalStorageDirectory(),
                        mContext.getResources().getString(R.string.app_name));
                if (!root.exists()) {
                    root.mkdirs();
                }
                java.io.File dataFolder = new java.io.File(root, "Data");
                if (!dataFolder.exists()) {
                    dataFolder.mkdirs();
                }
    
                java.io.File jsonFile = new java.io.File(dataFolder, FileName);
                Global.ShowLog("save_file_external_storage-jsonFile = " + jsonFile.getAbsolutePath());
    
                java.io.FileInputStream fin = null;
                fin = new java.io.FileInputStream(jsonFile);
    
                while ((ch = fin.read()) != -1)
                    strContent.append((char) ch);
    
                fin.close();
    
            } catch (Exception e) {
                Global.ShowLog("save_file_external_storage-error = " + e.getMessage());
            }
    
            try {
                FileData = java.net.URLDecoder.decode(strContent.toString(), "UTF-8");
            } catch (java.io.UnsupportedEncodingException uee) {
            }
    
            return FileData;
        }
     

java

android

storage

android-external-storage

0 Answers

Your Answer

Accepted video resources