3

I written a application which install the apk to device. I stored the apk in sd card. I tried Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File("/sdcard/MyApp.apk")), "application/vnd.android.package-archive"); startActivity(intent);

But I will get a window to ask wether to install or not. I do not need user intervention to install my .apk. What I can try?

So i tried to install using command line arguement Runtime.getRuntime() .exec("adb -d install /sdcard/MyApp.apk");

I am getting null environment error. How can I access to apk in sd card and how can I install it?

Thanks for the help.

thej
  • 648
  • 10
  • 33
  • http://stackoverflow.com/questions/8425201/installing-an-android-apk-programmatically-as-part-of-a-test-framework – user219882 Dec 28 '12 at 12:55

2 Answers2

2

I do not believe this is possible. If it was what would stop people from writing apps that install rouge apps and viruses. If you have a legit reason for having it install an apk then just request the user to install it and explain what its for.

Also its part of android security procedure so users can see the requested permissions and agree to them before an app can work on the device.

mpeerman
  • 2,050
  • 2
  • 16
  • 16
  • Can't I do this from command line arguments? Run the commands using a application which install myapp to the device. – thej Dec 28 '12 at 13:02
  • Yes you can install an app from the command line on a computer with the android sdk. This is allowed because it requires physical access to the device. – mpeerman Dec 28 '12 at 13:06
  • How can I do the same when myapp.apk is on my sdcard. – thej Dec 28 '12 at 13:07
  • You cant you can raise an intent like you have and request the user to install. But you cannot install any app without user approval – mpeerman Dec 28 '12 at 13:08
  • Thanks. I will change my approach for my problem – thej Dec 28 '12 at 13:10
  • No problem. If you have any more questions feel free to ask. – mpeerman Dec 28 '12 at 13:14
0

@thej: no way.Want to agree with android security procedure and then only you can install.

Because android gives more importance to OS. Since Android OS is like a bulletproof and apps

are sticked in that bulletproof. So android protects OS by checking the security of apps and

then provides user to install.

Shadow
  • 6,864
  • 6
  • 44
  • 93