[android-developers] Re: Sharing files between apps

2011-01-16 Thread John Gaby
 If you want to find out about an application, use
 Context.createPackageContext() to create a Context configured for another
 application.


This seems to be what I am looking for, however, when I call it with
the package name of the other app, it returns null (I get nothing from
logCat either).  I can use the PackageManager and retrieve the info
for that same package, so I am pretty sure I have the name correct and
the app is installed.  Do you have any ideas about what might be
wrong?

  And if you are using sharedUserId for this...  please do reconsider, this
 locks you into that forever and has pretty deep repercussions on the apps
 since they are now one unified entity whose permissions must be the union of
 both apps etc.)

I am using a sharedUserId, however, the two apps are unified.  In
fact, I would much rather have just a SINGLE app.  However, I want the
user to be able to install the app to the SD card, but it includes a
AppWidget component (which is optionally used) which cannot reside on
the SC card.  This seems to be forcing me to create two apps, may main
app, and a separate app to handle the AppWidget.  If there is a better
way to do this, I am all ears.

Thanks

On Jan 16, 2:54 pm, Dianne Hackborn hack...@android.com wrote:
 That can break, there is no guarantee the apps are installed the same place,
 for example if one is on the SD card and one isn't.

 If you want to find out about an application, use
 Context.createPackageContext() to create a Context configured for another
 application.

 (I assume you are doing tricks like creating the files world read/write to
 allow access between them.  If so, note this can open up security holes.  I
 would strongly recommend using one of the standard facilities for
 interacting between them, such as a receiver, service, or content provider.
  And if you are using sharedUserId for this...  please do reconsider, this
 locks you into that forever and has pretty deep repercussions on the apps
 since they are now one unified entity whose permissions must be the union of
 both apps etc.)



 On Sun, Jan 16, 2011 at 2:27 PM, John Gaby jg...@gabysoft.com wrote:
  I have two applications which can access each others files.  To get a
  path to a file in the other app, I am using the context.getDir(...)
  function to get a path to the file for the running app, and then
  changing the package name component of that path to the package name
  of the other app.  This seems to work, but I am wondering if this is a
  reliable way of doing this, or if there is another more appropriate
  way.

  Thanks.

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

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support, and so won't reply to such e-mails.  All such
 questions should be posted on public forums, where I and others can see and
 answer them.

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


Re: [android-developers] Re: Sharing files between apps

2011-01-16 Thread Dianne Hackborn
On Sun, Jan 16, 2011 at 4:21 PM, John Gaby jg...@gabysoft.com wrote:

 This seems to be what I am looking for, however, when I call it with
 the package name of the other app, it returns null (I get nothing from
 logCat either).  I can use the PackageManager and retrieve the info
 for that same package, so I am pretty sure I have the name correct and
 the app is installed.  Do you have any ideas about what might be
 wrong?


Well no idea from just your paragraph description there. :)  This API
certainly works -- it is used a lot, for things like inflating the UI of app
widgets.


 I am using a sharedUserId, however, the two apps are unified.  In
 fact, I would much rather have just a SINGLE app.  However, I want the
 user to be able to install the app to the SD card, but it includes a
 AppWidget component (which is optionally used) which cannot reside on
 the SC card.  This seems to be forcing me to create two apps, may main
 app, and a separate app to handle the AppWidget.  If there is a better
 way to do this, I am all ears.


Oh my.  Well personally I would really strongly discourage doing that.  I
think you are going to end up with continual pain in app maintenance, not to
mention support for your users dealing with multiple apps like this.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

[android-developers] Re: Sharing files between apps

2011-01-16 Thread John Gaby
 Well no idea from just your paragraph description there. :)  This API
 certainly works -- it is used a lot, for things like inflating the UI of app
 widgets.


The following is the routine that I wrote to test the function.  The
call to manager.getPackageInfo works, but the call to
GetPackageContents returns null.

private void Test()
{
String pkg = com.gabysoft.quizardwidget;

PackageManager manager= getPackageManager();
PackageInfoinfo;

try
{
info = manager.getPackageInfo(pkg, 0);

int v = info.versionCode;
}
catch (NameNotFoundException e)
{
}

Context c = GetPackageContext(pkg, CONTEXT_INCLUDE_CODE);
File file = c.getDir(data, Context.MODE_PRIVATE);
String path = file.getAbsolutePath();
}

 Oh my.  Well personally I would really strongly discourage doing that.  I
 think you are going to end up with continual pain in app maintenance, not to
 mention support for your users dealing with multiple apps like this.

I actually tend to agree, but I really hate to force the user to
install the app to internal memory (there is a fair amount of
content).  The feedback I have gotten so far from the users that I
have asked is that they would rather see a separate app than loose the
ability to install on the SD card.  Is there ANY other way to deal
with this?

Thanks.

On Jan 16, 4:46 pm, Dianne Hackborn hack...@android.com wrote:
 On Sun, Jan 16, 2011 at 4:21 PM, John Gaby jg...@gabysoft.com wrote:
  This seems to be what I am looking for, however, when I call it with
  the package name of the other app, it returns null (I get nothing from
  logCat either).  I can use the PackageManager and retrieve the info
  for that same package, so I am pretty sure I have the name correct and
  the app is installed.  Do you have any ideas about what might be
  wrong?

 Well no idea from just your paragraph description there. :)  This API
 certainly works -- it is used a lot, for things like inflating the UI of app
 widgets.

  I am using a sharedUserId, however, the two apps are unified.  In
  fact, I would much rather have just a SINGLE app.  However, I want the
  user to be able to install the app to the SD card, but it includes a
  AppWidget component (which is optionally used) which cannot reside on
  the SC card.  This seems to be forcing me to create two apps, may main
  app, and a separate app to handle the AppWidget.  If there is a better
  way to do this, I am all ears.

 Oh my.  Well personally I would really strongly discourage doing that.  I
 think you are going to end up with continual pain in app maintenance, not to
 mention support for your users dealing with multiple apps like this.

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support, and so won't reply to such e-mails.  All such
 questions should be posted on public forums, where I and others can see and
 answer them.

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


Re: [android-developers] Re: Sharing files between apps

2011-01-16 Thread Dianne Hackborn
On Sun, Jan 16, 2011 at 5:19 PM, John Gaby jg...@gabysoft.com wrote:

 The following is the routine that I wrote to test the function.  The
 call to manager.getPackageInfo works, but the call to
 GetPackageContents returns null.


What is GetPackageContext in your code?  Is that just a typo and should be
getPackageContext?


 I actually tend to agree, but I really hate to force the user to
 install the app to internal memory (there is a fair amount of
 content).  The feedback I have gotten so far from the users that I
 have asked is that they would rather see a separate app than loose the
 ability to install on the SD card.  Is there ANY other way to deal
 with this?


Well for transferring data between apps, I will say the same thing I already
have: I would very much recommend using a receiver, service, or content
provider.  Don't use shared user IDs.  Your widget could just for example
send a broadcast to your app when it needs to populate data.  As a bonus,
your main app could be the one in charge of the data and send a broadcast to
the widget app when it has changed to give it the new data.  I think you'll
find this a much cleaner solution than trying to directly access data files.

At any rate, offering your users a small add-on app that they can optionally
download to provide a widget is probably not too bad I guess.  Heck you
could turn it into an advantage and make it paid so it is an additional
feature they can purchase for your app. ;)

But I do think you should architect it so that the interaction between these
pieces is through app components, not data.  It will result in a much
cleaner and more maintainable design.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

[android-developers] Re: Sharing files between apps

2011-01-16 Thread John Gaby
 What is GetPackageContext in your code?  Is that just a typo and should be
 getPackageContext?

Well, now don't I feel sheepish!  It was indeed a typo, and the ever
so helpful editor created a GetPackageContext for me and returned
null.  Sorry about wasting your time.

As for your other suggestion about using a broadcast to get the data,
that does seem like a good idea.  In fact, the widget itself uses a
broadcast intent when the user click on it to get the next set of data
to display.  I assume that I could send that broadcast to my main app
just as easily as it does to the Widget app.

Thanks for the help and suggestions.


On Jan 16, 5:57 pm, Dianne Hackborn hack...@android.com wrote:
 On Sun, Jan 16, 2011 at 5:19 PM, John Gaby jg...@gabysoft.com wrote:
  The following is the routine that I wrote to test the function.  The
  call to manager.getPackageInfo works, but the call to
  GetPackageContents returns null.

 What is GetPackageContext in your code?  Is that just a typo and should be
 getPackageContext?

  I actually tend to agree, but I really hate to force the user to
  install the app to internal memory (there is a fair amount of
  content).  The feedback I have gotten so far from the users that I
  have asked is that they would rather see a separate app than loose the
  ability to install on the SD card.  Is there ANY other way to deal
  with this?

 Well for transferring data between apps, I will say the same thing I already
 have: I would very much recommend using a receiver, service, or content
 provider.  Don't use shared user IDs.  Your widget could just for example
 send a broadcast to your app when it needs to populate data.  As a bonus,
 your main app could be the one in charge of the data and send a broadcast to
 the widget app when it has changed to give it the new data.  I think you'll
 find this a much cleaner solution than trying to directly access data files.

 At any rate, offering your users a small add-on app that they can optionally
 download to provide a widget is probably not too bad I guess.  Heck you
 could turn it into an advantage and make it paid so it is an additional
 feature they can purchase for your app. ;)

 But I do think you should architect it so that the interaction between these
 pieces is through app components, not data.  It will result in a much
 cleaner and more maintainable design.

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support, and so won't reply to such e-mails.  All such
 questions should be posted on public forums, where I and others can see and
 answer them.

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