On Jul 25, 2012, at 2:07 PM, Matthieu Laban <m...@flyingdevelopmentstudio.com> 
wrote:
> I've tried using Assets.Open but accessing the Length or Position property 
> throws an exception. Tried setting the access flag to Access.Random but this 
> made no difference. 

They throw an exception because there's no way for them to work. 
AssetManager.open() returns a java.io.InputStream:

        
http://developer.android.com/reference/android/content/res/AssetManager.html#open(java.lang.String)

java.io.InputStream, meanwhile, has no API to access stream location:

        http://developer.android.com/reference/java/io/InputStream.html

AssetManager.open() will return a subclass; you can access the actual 
InputStream instance by casing the Stream returned by AssetManager.Open() to an 
InputStreamInvoker [0] and using InputStreamInvoker.BaseInputStream [1], but I 
doubt that the actual type will permit accessing stream position either.

> The solutions I've found online were to transfer all the contents to a memory 
> stream. It seems like a bad idea in the cases where I read files that are a 
> few MB in size...

I would instead suggest copying the resource into the cache directory:

        http://androidapi.xamarin.com/?link=P%3aAndroid.Content.Context.CacheDir

> Any advice? Should I use something else for my resources?

Does it need to be a Resource? The only times it needs to be a Resource is when 
you need to have a Resource ID because you're referencing it within a .axml 
layout file, or because some API you're using only deals with Resource IDs. If 
you don't need a Resource, you could instead use .NET Embedded Resources (Build 
action: EmbeddedResource) and then use Assembly.GetManifestResourceStream() to 
read it:

        
http://androidapi.xamarin.com/?link=M:System.Reflection.Assembly.GetManifestResourceStream(string)

 - Jon

[0] http://androidapi.xamarin.com/?link=T%3aAndroid.Runtime.InputStreamInvoker
[1] 
http://androidapi.xamarin.com/index.aspx?link=P%3aAndroid.Runtime.InputStreamInvoker.BaseInputStream

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

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

Reply via email to