Copy apk located in / data / app / programmatically

0

Hello , I'd like to copy an apk located in the / data / app / folder. But the apk is not being copied, only the folder is created, it follows the code:

InputStream input;
            String apkPath = "/data/app/com.app.exemplo/base.apk";
            String sdPath = Environment.getExternalStorageDirectory().getPath();
            try {
                File apk = new File(Environment.getDataDirectory()+apkPath);
                File directory = new File(sdPath + "/copiarAqui/");
                if (!directory.exists()){
                    directory.mkdirs();
                }
                input = new FileInputStream(Environment.getDataDirectory()
                        + apkPath);
                OutputStream output = new FileOutputStream(directory.getPath() +
                        "apktest.apk");
                byte[] buffer = new byte[1024];
                int lenght;
                while ((lenght = input.read(buffer)) > 0) {
                    output.write(buffer, 0, lenght);
                }

                output.flush();
                output.close();
                input.close();
                Toast.makeText(getActivity(), "Copiado com sucesso!", Toast.LENGTH_SHORT).show();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

The permissions are already in my application:

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

Can anyone tell me the problem?

    
asked by anonymous 07.09.2016 / 14:10

0 answers