1

Can I install apk file without downloading? The apk file is on the server. I tried the code below but it doesn't work:

public static void InstallProgram(Uri uri, Context context){
    Intent intent = new Intent(Intent.ACTION_VIEW);           
    intent.setDataAndType(uri,"application/vnd.android.package-archive");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     
    context.startActivity(intent);
}

Where uri is http://192.168.43.1:6789/mobile_base/test.apk. It returns an error:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://192.168.43.1:6789/mobile_base/test.apk typ=application/vnd.android.package-archive flg=0x10000000 }
NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
Nolesh
  • 6,848
  • 12
  • 75
  • 112
  • 1
    see this http://stackoverflow.com/questions/5952516/install-apk-from-url – vnshetty Jun 08 '12 at 04:33
  • I also want to install android application without downloading from my own server. Did you find the solution? – Manoj Oct 27 '12 at 06:42
  • Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(downloadPath + fileName)), "application/vnd.android.package-archive"); – Johan May 31 '13 at 08:42

2 Answers2

5

you can use this code .may be solve the problem

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://192.168.43.1:6789/mobile_base/test.apk"));
startActivity(intent);
Amit kumar
  • 1,585
  • 2
  • 16
  • 27
2

For this your android application must have uploaded into the android market. when you upload it on the android market then use the following code to open the market with your android application.

    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=<packagename>"));
startActivity(intent);

If you want it to download and install from your own server then use the following code

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.example.com/sample/test.apk"));
    startActivity(intent);
Amit Thaper
  • 2,117
  • 4
  • 26
  • 49
  • 2
    Thanks. You forgot about `intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);` But I don't want to download file. So if there is no any solution. I'm going to download it first before install. – Nolesh Jun 08 '12 at 05:11