0

This is Code to Create Folder inside a file in SD card in Android 6.0, Am using Flex Code , Added ANE Extension, AIR version 24.0 and swf = 35. working in debug Mode, But not working Release Mode. Please Help to me.

if(library.Utility.getDeviceType() == "ANDROID")
{

                var permissionCheck : File; 
                permissionCheck  = new File(pdfFile.nativePath);
                permissionCheck.addEventListener(PermissionEvent.PERMISSION_STATUS , function permissionStatusHandler( e : PermissionEvent ) :void
                {                        
                    permissionCheck.removeEventListener(PermissionEvent.PERMISSION_STATUS , permissionStatusHandler);
                    if(e.status == PermissionStatus.GRANTED)
                    {                            
                        //  save your file
                        pdfFolder = File.userDirectory.resolvePath(".Folder");
                        if(!pdfFolder.exists)
                            pdfFolder.createDirectory();
                        trace(pdfFolder.nativePath);
                        //pdfFile =  File.applicationStorageDirectory.resolvePath("pdf/" +file);
                        var targetFile:File = File.userDirectory.resolvePath(".Folder/" +file);
                        trace(targetFile.nativePath);
                        if(targetFile.exists)
                            targetFile.deleteFile();

                        if(!targetFile.exists && pdfFile.exists)
                        {
                            try
                            {
                                pdfFile.copyTo(targetFile);
                                Template.showFile(targetFile.nativePath);
                            }
                            catch(error:Error)
                            {
                                Popup.showMessage("PDF Viewer", "Unable to open " + file + ". File does not exists. " + error.message);
                                trace("Error:" + error.message);
                            }
                        }
                        else
                        {
                            Popup.showMessage("PDF Viewer", "Unable to find " + file + ". File does not exists.");
                        }

                    }
                    else
                    {
                        //showPermissionError();
                        trace("Error"+ pdfFolder.nativePath);

                    }

                });

                try
                {
                    permissionCheck.requestPermission();

                }
                catch(error : Error)
                {
                    trace("Error:" + error.message);
                }

            }

1 Answers1

2

You should try to write your traces (like permission status, pdfFolder.exists and so on) into a textField so you can localize the problem in the release mode.

Also listen to IOErrorEvent.IO_ERROR and SecurityErrorEvent.SECURITY_ERROR on your targetFile and trace them to the textField, maybe there are some problems with that.

Normally you should save the application files in the File.applicationStorageDirectory (and not in the userDirectory), but I guess you want the user to be able to access the files on his own?

Try a folder without the dot ("Folder" instead of ".Folder").

On Android you'll need to grant permissions for writing the files in your application.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>             
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Philarmon
  • 1,796
  • 1
  • 10
  • 14