On Nov 22, 2011, at 11:55 AM, Steve Sharrock wrote:
> I'm trying to write a common file that three of our MonoDroid applications 
> can all read/write. I tried the following directory:
>  
> string p = System.Environment.GetFolderPath( 
> System.Environment.SpecialFolder.CommonApplicationData );

At this time, SpecialFolder.CommonApplicationData is /usr/share, which doesn't 
exist on Android (and which means it'll probably fail on Windows, for that 
matter...):

        
https://github.com/mono/mono/blob/master/mcs/class/corlib/System/Environment.cs#L689

There are two basic solutions I can think of: using the SD card, and using 
sharedUserId.

To use the SD card, you'll need to the WRITE_EXTERNAL_STORAGE permission, and 
then your have your apps just "agree" on the directory to write to. See also 
Context.GetExternalFilesDir():

        
http://androidapi.xamarin.com/monodoc.ashx?link=M%3aAndroid.Content.Context.GetExternalFilesDir(System.String)

To use sharedUserId, your packages must have the same 
/manifest/@android:sharedUserId value:

        
http://developer.android.com/guide/topics/manifest/manifest-element.html#uid

We currently don't have a custom attribute to generate the <manifest/> element, 
so you'll need to add this attribute within Properties\AndroidManifest.xml.

Once your packages have the same sharedUserId value, they'll be able to access 
each others private data.

That just leaves determining which directory to use, which can be gotten from 
ApplicationInfo.DataDir:

        
http://androidapi.xamarin.com/index.aspx?link=P%3aAndroid.Content.PM.ApplicationInfo.DataDir

To get the ApplicationInfo data, use Context.PackageManager > 
PackageManager.GetApplicatoinInfo():

        
http://androidapi.xamarin.com/index.aspx?link=M%3aAndroid.Content.PM.PackageManager.GetApplicationInfo(System.String%2cSystem.Int32)

So you could agree that package com.example.Data contains your data files, then 
call `this.PackageManager.GetApplicationInfo ("com.example.Data", 0).DataDir` 
to obtain the directory to write to.

Thanks,
 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to