java.io.filenotfoundexeption:/storage/sdcard/app.apk打开失败的Eacces(权限被拒绝)

时间:2015-04-04 21:14:14

标签: android permissions copy android-external-storage

我想将我的apk文件从我的应用程序的de package复制到外部存储器:

课堂副本:

package com.pfe.bls;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import android.os.Environment;

public class Copyapk {
    public static void copy() throws IOException {
        String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
        String fileName = "app.apk";
        FileInputStream inStream = new FileInputStream("/data/data/com.pfe.bls/app.apk");
        FileOutputStream outStream = new FileOutputStream(baseDir + File.separator + fileName);
        FileChannel inChannel = inStream.getChannel();
        FileChannel outChannel = outStream.getChannel();
        inChannel.transferTo(0, inChannel.size(), outChannel);
        inStream.close();
        outStream.close();
    }   

}
在clicklistener中的mainactivity中我的méthod的上诉:

btn_createApp.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
    try {
                    Copyapk.copy();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
android清单中的

权限:

 <uses-permission android:name="android.permissions.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS" />

1 个答案:

答案 0 :(得分:0)

您的数据文件夹存储在哪里? 它是在外部存储或应用程序存储中。要从应用程序存储目录访问它,您应该使用以下

PackageManager m = getPackageManager();
String s = getPackageName();
try {
    PackageInfo p = m.getPackageInfo(s, 0);
    s = p.applicationInfo.dataDir;
    } catch (NameNotFoundException e) {
  Log.w("yourtag", "Error not found ", e);
    }