The package manager way will not work, you need the permission you
referenced, INSTALL_PACKAGES, which only the system has and is not
obtainable by user-installed applications.

I think your Intent-based method should work, I believe this is more
or less what the browser does when you download an APK from the
internet. I have two thoughts. First, you haven't specified a proper
Uri, you've specified a file path, try file:///data/data/... Second,
I'm not sure you can place the file in your app's private directory
and have this work, to remove this variable, try placing the APK on
the SD card.

As far as removing packages, I'm not sure, I'm not sure what Intent
you would use to do this, although certainly some Intent exists,
albeit probably private/undocumented. You could watch the logcat
output when you go into the application manager from settings.

Cheers,
Justin
Android Team @ Google

On Jul 1, 6:22 am, calleandersson <[email protected]> wrote:
> Hi,
>
> I am going to create an application (using Android 1.5) which can
> download and install other applications and also be able to remove
> these applications when needed. I have tried to do this in two
> different ways but havn't had any success:
>
> -- A: the PackageManager way --
>
> Using the following code:
>
> getPackageManager().installPackage(Uri.parse(url));
>
> an SecurityException occur since (as I understand) it isn't possible
> for an application to be granted the INSTALL_PACKAGES permission
> (which is needed by the installPackage() method) unless the program
> has system rights.
>
> A1. Is it correct that system rights is needed by an application to be
> granted INSTALL_PACKAGES permission?
>
> A2. How can an application acquire system rights?
>
> A3. Will this approach generate some kind of platform specific install
> popups (or something like that) or could an application be installed
> without any user interaction required?
>
> -- B: the Intent way --
>
> I download an .apk-file using code similar to the following code:
>
> URL sourceUrl = new URL(source);
> Object data = sourceUrl.getContent();
> String fileName = sourceUrl.getFile().substring(fileName.lastIndexOf
> ('/') + 1);
> // create/open file in the 'data/data/<app namespace>/files' directory
> FileOutputStream fos = openFileOutput(fileName, Context.MODE_PRIVATE);
> int read = 0;
> byte[] buffer = new byte[512];
> BufferedInputStream bis = new BufferedInputStream((InputStream) data);
> do{
>         read = bis.read(buffer);
>         if(read > 0){
>                 fos.write(buffer, 0, read);
>         }
>
> }while(read != -1);
>
> and then i try to invoke an installation of the application by using
> the following code (which I belive should bring the system UI up for
> the user to confirm the install):
>
> Intent intent = new Intent();
> intent.setAction(android.content.Intent.ACTION_VIEW);
> intent.setDataAndType(Uri.parse("/data/data/test.calle.helloworld/
> files/AndroidHelloWorld.apk"), "application/vnd.android.package-
> archive");
> startActivity(intent);
>
> but this only generates an ActivityNotFoundException:
> 07-01 10:11:05.354: ERROR/AndroidRuntime(2480):
> android.content.ActivityNotFoundException: No Activity found to handle
> Intent { action=android.intent.action.VIEW data=/data/data/
> test.calle.helloworld/files/AndroidHelloWorld.apk type=application/
> vnd.android.package-archive }
>
> B1. What am I doing wrong/missing in the attempt to install the
> downloaded application?
>
> B2. Will this approach bring the system UI up (for the user to confirm
> the install) or have I misunderstood something?
>
> B3. Could I use the same Intent code to start an already installed
> application or do I need change some input data?
>
> B4. Is it possible to initiate an uninstall of an application with a
> similar approach (without beeing granted the REMOVE_PACKAGES
> permission)?
>
> B5. Is there some cleaner/easier way of downloading an entire file
> from the internet to the file system and should I use
> 'Context.MODE_PRIVATE' when I call the openFileOutput() method?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to