i want to copy my apk file from de package of my application to the external storage:
class copy:
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();
}
}
l'appel of my méthod in mainactivity inside clicklistener :
btn_createApp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Copyapk.copy();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
permission in android manifest:
<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" />
Where is your data folder stored? Is it in the external storage or application storage. For accessing it from application storage directory, you should use use following
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.