Install apk from assets android
- Copy/put your apk file in assets folder of your project
- Set onClick event of button to install apk. Copy and paste following code ===============================================
- Its done
public void loadMyApk()
{
copyAssets(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + "BS.apk")), "application/vnd.android.package-archive"); startActivityForResult(intent, 4);
}
===============================================
private void copyAssets()
{
AssetManager assetManager = getAssets(); String[] files = null; try { files = assetManager.list(""); } catch (IOException e) { Log.e("tag", e.getMessage()); } for(String filename : files) { InputStream in = null; OutputStream out = null; try { //fileone=filename; in = assetManager.open(filename); out = new FileOutputStream("/sdcard/" + filename); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch(Exception e) { Log.e("tag", e.getMessage()); } }
}
===============================================
private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024]; int read; while((read = in.read(buffer)) != -1){ out.write(buffer, 0, read); }
}
===============================================
You have a example application?
ReplyDeleteYaa... but source code is too big. Very soon will share a demo. Thanks for asking.
ReplyDelete