0

I am building an android app which depends on the other application ,actually the other application is the writing pad which I want to install with the application,I am trying to place the apk file inside the raw folder and trying to access it like this:

      Uri app= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.app);

Is it feasible? If yes how can I install this app?

Jongware
  • 22,200
  • 8
  • 54
  • 100
Talib
  • 1,134
  • 5
  • 31
  • 58

2 Answers2

1

Place your apk in asset folder and change myAPKFile.apk to your apk file name and use this function to install your apk.

Permissions required:

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


private boolean InstallmyAPK(){

AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
File myAPKFile = new File(Environment.getExternalStorageDirectory().getPath()+"/myAPKFile.apk");

try {

    if(!myAPKFile.exists()){
        in = assetManager.open("myAPKFile.apk");
        out = new FileOutputStream(myAPKFile);

        byte[] buffer = new byte[1024];
        int read;
        while((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }

        in.close();
        in = null;

        out.flush();
        out.close();
        out = null;
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(myAPKFile),
            "application/vnd.android.package-archive");
    startActivity(intent);
    return true;

} catch(Exception e) {return false;}

}
H4SN
  • 1,482
  • 3
  • 24
  • 43
  • 1
    i am in same situation some days before.. this will copy your apk file to sd card if you want to remove you can delete it later – H4SN Dec 15 '14 at 13:08
0

try (I think this question has already been answered before here: Install Application programmatically on Android)

  Intent promptInstall = new Intent(Intent.ACTION_VIEW)
        .setDataAndType(Uri.parse("file:///path/to/your.apk"), 
                        "application/vnd.android.package-archive");
    startActivity(promptInstall); 
Community
  • 1
  • 1
J.K
  • 2,290
  • 1
  • 18
  • 29