[android-beginners] Re: How to install and run applications from within another application?

2009-07-10 Thread Yasser

For getLaunchIntentForPackage(), it says it is undefined for type
PackageManager and hence code cannot compile?
i can see the other methods when I put . after getPackageManager()
except this one.

Thanks
Yasser

On Jul 6, 10:39 am, Justin (Google Employee) j...@google.com
wrote:
   How does the process for retrieving system rights look like?

 Its a matter of signatures. Whoever signs the system is also going to
 need to sign any app that wants system privileges.

  I suppose this problem
  shouldn't exist if I was able to save the .apk file in the private
  directory of my application and then invoke the system install UI on
  the file.

 Well, no, you can't have your cake and eat it to. The package manager
 needs to be able to read the APK file to install the app. In order to
 do this you need to place the APK in a world-readable location because
 you can't have the same UID or GID as the package manager. No matter
 what you do, if you want to allow the package manager to read the
 file, everyone can. Now, if you put the file in your private directory
 and set the mode to MODE_WORLD_READABLE, the package manager may be
 able to read the file, I think it should be able to. Everyone else
 can, but they would have to know the exact path because I don't
 believe they can list the directory in which the file resides.

 Now, regardless of where the APK is placed, you should probably delete
 it after installation, otherwise you're at least doubling storage
 space required per application. If you delete the APK after its
 installed, you also fix your install only to device downloaded on.

 Cheers,
 Justin
 Android Team @ Google

 On Jul 2, 3:48 am, calleandersson calleanders...@hotmail.com wrote:



  I have been testing with the 'file://' prefix and got the following
  results:

  When saving an .apk file in the private directory of my application
  and trying to invoke the system installation UI, an parse error
  occured due to permission issues:
    07-02 07:15:27.826: WARN/zipro(726): Unable to open zip '/data/data/
  test.calle.helloworld/files/AndroidHelloWorld.apk': Permission denied
    07-02 07:15:27.826: DEBUG/asset(726): failed to open Zip archive '/
  data/data/test.calle.helloworld/files/AndroidHelloWorld.apk'
    07-02 07:15:27.846: WARN/PackageParser(726): Unable to read
  AndroidManifest.xml of /data/data/test.calle.helloworld/files/
  AndroidHelloWorld.apk
    07-02 07:15:27.846: WARN/PackageParser(726):
  java.io.FileNotFoundException: AndroidManifest.xml
     ...
    07-02 07:15:27.856: WARN/PackageInstaller(726): Parse error when
  parsing manifest. Discontinuing installation

  When I saved the .apk file on the SD card, everything went as supposed
  and the system installation UI was displayed.

  So far so good. However, I only want a downloaded .apk file to be
  installed on the same phone which downloaded it. If the application is
  placed on the SD card, wouldn't it be possible to use the same SD card
  in another phone (or copy the .apk file to another SD card used by
  another phone) and install the application on that phone too? Am I
  correct in these assumtions?

  With regards to what I wrote above, is it somehow possible to restrict
  an application file from beeing installed on any other phone except
  the very same phone which downloaded the .apk file (using my
  application)? Is system rights needed? I suppose this problem
  shouldn't exist if I was able to save the .apk file in the private
  directory of my application and then invoke the system install UI on
  the file.

  Regards,
  Calle

  On 1 Juli, 18:22, calleandersson calleanders...@hotmail.com wrote:

   Hi Justin,

   Thanks for the tips about the 'file://' prefix and SD card, I will
   look into that tomorrow.

   How does the process for retrieving system rights look like? Is it the
   manufacturer of an Android device which decides if an application
   should have system rights? I suppose that that kind of clients must be
   installed/included in the device before it is released or am I wrong?

   Is there somehow possible to simulate that an application has system
   rights in the Emulator?

   By the way, I was thinking of using the same Intent code to start an
   already installed application but, currently, I'm using the following
   code which seems to work pretty well (and the class name doesn't need
   to be specified):
   Intent intent = getPackageManager().getLaunchIntentForPackage
   (packageName);
   startActivity(intent);

   Regards,
   Calle

   On 1 Juli, 17:18, Justin (Google Employee) j...@google.com wrote:

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 

[android-beginners] Re: How to install and run applications from within another application?

2009-07-06 Thread Justin (Google Employee)

  How does the process for retrieving system rights look like?

Its a matter of signatures. Whoever signs the system is also going to
need to sign any app that wants system privileges.

 I suppose this problem
 shouldn't exist if I was able to save the .apk file in the private
 directory of my application and then invoke the system install UI on
 the file.

Well, no, you can't have your cake and eat it to. The package manager
needs to be able to read the APK file to install the app. In order to
do this you need to place the APK in a world-readable location because
you can't have the same UID or GID as the package manager. No matter
what you do, if you want to allow the package manager to read the
file, everyone can. Now, if you put the file in your private directory
and set the mode to MODE_WORLD_READABLE, the package manager may be
able to read the file, I think it should be able to. Everyone else
can, but they would have to know the exact path because I don't
believe they can list the directory in which the file resides.

Now, regardless of where the APK is placed, you should probably delete
it after installation, otherwise you're at least doubling storage
space required per application. If you delete the APK after its
installed, you also fix your install only to device downloaded on.

Cheers,
Justin
Android Team @ Google

On Jul 2, 3:48 am, calleandersson calleanders...@hotmail.com wrote:
 I have been testing with the 'file://' prefix and got the following
 results:

 When saving an .apk file in the private directory of my application
 and trying to invoke the system installation UI, an parse error
 occured due to permission issues:
   07-02 07:15:27.826: WARN/zipro(726): Unable to open zip '/data/data/
 test.calle.helloworld/files/AndroidHelloWorld.apk': Permission denied
   07-02 07:15:27.826: DEBUG/asset(726): failed to open Zip archive '/
 data/data/test.calle.helloworld/files/AndroidHelloWorld.apk'
   07-02 07:15:27.846: WARN/PackageParser(726): Unable to read
 AndroidManifest.xml of /data/data/test.calle.helloworld/files/
 AndroidHelloWorld.apk
   07-02 07:15:27.846: WARN/PackageParser(726):
 java.io.FileNotFoundException: AndroidManifest.xml
    ...
   07-02 07:15:27.856: WARN/PackageInstaller(726): Parse error when
 parsing manifest. Discontinuing installation

 When I saved the .apk file on the SD card, everything went as supposed
 and the system installation UI was displayed.

 So far so good. However, I only want a downloaded .apk file to be
 installed on the same phone which downloaded it. If the application is
 placed on the SD card, wouldn't it be possible to use the same SD card
 in another phone (or copy the .apk file to another SD card used by
 another phone) and install the application on that phone too? Am I
 correct in these assumtions?

 With regards to what I wrote above, is it somehow possible to restrict
 an application file from beeing installed on any other phone except
 the very same phone which downloaded the .apk file (using my
 application)? Is system rights needed? I suppose this problem
 shouldn't exist if I was able to save the .apk file in the private
 directory of my application and then invoke the system install UI on
 the file.

 Regards,
 Calle

 On 1 Juli, 18:22, calleandersson calleanders...@hotmail.com wrote:



  Hi Justin,

  Thanks for the tips about the 'file://' prefix and SD card, I will
  look into that tomorrow.

  How does the process for retrieving system rights look like? Is it the
  manufacturer of an Android device which decides if an application
  should have system rights? I suppose that that kind of clients must be
  installed/included in the device before it is released or am I wrong?

  Is there somehow possible to simulate that an application has system
  rights in the Emulator?

  By the way, I was thinking of using the same Intent code to start an
  already installed application but, currently, I'm using the following
  code which seems to work pretty well (and the class name doesn't need
  to be specified):
  Intent intent = getPackageManager().getLaunchIntentForPackage
  (packageName);
  startActivity(intent);

  Regards,
  Calle

  On 1 Juli, 17:18, Justin (Google Employee) j...@google.com wrote:

   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 

[android-beginners] Re: How to install and run applications from within another application?

2009-07-02 Thread calleandersson

I have been testing with the 'file://' prefix and got the following
results:

When saving an .apk file in the private directory of my application
and trying to invoke the system installation UI, an parse error
occured due to permission issues:
  07-02 07:15:27.826: WARN/zipro(726): Unable to open zip '/data/data/
test.calle.helloworld/files/AndroidHelloWorld.apk': Permission denied
  07-02 07:15:27.826: DEBUG/asset(726): failed to open Zip archive '/
data/data/test.calle.helloworld/files/AndroidHelloWorld.apk'
  07-02 07:15:27.846: WARN/PackageParser(726): Unable to read
AndroidManifest.xml of /data/data/test.calle.helloworld/files/
AndroidHelloWorld.apk
  07-02 07:15:27.846: WARN/PackageParser(726):
java.io.FileNotFoundException: AndroidManifest.xml
   ...
  07-02 07:15:27.856: WARN/PackageInstaller(726): Parse error when
parsing manifest. Discontinuing installation

When I saved the .apk file on the SD card, everything went as supposed
and the system installation UI was displayed.

So far so good. However, I only want a downloaded .apk file to be
installed on the same phone which downloaded it. If the application is
placed on the SD card, wouldn't it be possible to use the same SD card
in another phone (or copy the .apk file to another SD card used by
another phone) and install the application on that phone too? Am I
correct in these assumtions?

With regards to what I wrote above, is it somehow possible to restrict
an application file from beeing installed on any other phone except
the very same phone which downloaded the .apk file (using my
application)? Is system rights needed? I suppose this problem
shouldn't exist if I was able to save the .apk file in the private
directory of my application and then invoke the system install UI on
the file.

Regards,
Calle

On 1 Juli, 18:22, calleandersson calleanders...@hotmail.com wrote:
 Hi Justin,

 Thanks for the tips about the 'file://' prefix and SD card, I will
 look into that tomorrow.

 How does the process for retrieving system rights look like? Is it the
 manufacturer of an Android device which decides if an application
 should have system rights? I suppose that that kind of clients must be
 installed/included in the device before it is released or am I wrong?

 Is there somehow possible to simulate that an application has system
 rights in the Emulator?

 By the way, I was thinking of using the same Intent code to start an
 already installed application but, currently, I'm using the following
 code which seems to work pretty well (and the class name doesn't need
 to be specified):
 Intent intent = getPackageManager().getLaunchIntentForPackage
 (packageName);
 startActivity(intent);

 Regards,
 Calle

 On 1 Juli, 17:18, Justin (Google Employee) j...@google.com wrote:



  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 calleanders...@hotmail.com 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

[android-beginners] Re: How to install and run applications from within another application?

2009-07-02 Thread David Turner
On Wed, Jul 1, 2009 at 6:22 PM, calleandersson
calleanders...@hotmail.comwrote:


 Is there somehow possible to simulate that an application has system
 rights in the Emulator?


No, and very intentionally.





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How to install and run applications from within another application?

2009-07-01 Thread Justin (Google Employee)

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 calleanders...@hotmail.com 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 android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How to install and run applications from within another application?

2009-07-01 Thread calleandersson

Hi Justin,

Thanks for the tips about the 'file://' prefix and SD card, I will
look into that tomorrow.

How does the process for retrieving system rights look like? Is it the
manufacturer of an Android device which decides if an application
should have system rights? I suppose that that kind of clients must be
installed/included in the device before it is released or am I wrong?

Is there somehow possible to simulate that an application has system
rights in the Emulator?

By the way, I was thinking of using the same Intent code to start an
already installed application but, currently, I'm using the following
code which seems to work pretty well (and the class name doesn't need
to be specified):
Intent intent = getPackageManager().getLaunchIntentForPackage
(packageName);
startActivity(intent);

Regards,
Calle


On 1 Juli, 17:18, Justin (Google Employee) j...@google.com wrote:
 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 calleanders...@hotmail.com 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?- Dölj 
  citerad text -

 - Visa