As mentioned, use a MatrixCursor: http://developer.android.com/reference/android/database/MatrixCursor.html
Or you can derive directly from AbstractCursor and implement the full Cursor API if you want... more work, but ultimately would probably be a more efficient implementation. And actually for a case of just returning a single row with two columns containing strings, probably simpler to just do AbstractCursor -- implement getCount() to return 2, getString() the two string values, and the other abstract methods can be implemented to return whatever. On Wed, Apr 27, 2011 at 4:01 AM, Paul <[email protected]> wrote: > Ok, so the UriImage code IS expecting a Cursor that contains two > columns, _data and mime_type. Silly question maybe, but how do I > create a Cursor containing these columns from a static PNG file > without storing the corresponding data in a database? I am now > handling the Uri for the image (content://package.name/#/png) in my > ContentProvider.query(), and can fudge the values from the database if > needed (SELECT name AS '_data', etc), but I am not, and can't really > store mime type... as it is possible for the static file to be in any > number of formats (png, svg, etc). > > Any pointers appreciated on how to handle this. > > Paul > > On Apr 26, 4:13 pm, Kostya Vasilyev <[email protected]> wrote: > > 26.04.2011 19:53, Paul пишет: > > > > > Right, but in my case I am dealing with a physical file, not data > > > stored in a database. I have physical .png files located in the > > > applications /files directory that I want to be able to send/share. > > > > A ContentProvider doesn't have to be backed by a database. > > > > Since yours is not, you can use MatrixCursor to build one row of data in > > memory in your query(). > > > > http://developer.android.com/reference/android/database/MatrixCursor.... > > > > > As I was originally copying the file over to the cache directory and > > > making them world readable via .exec(), I asked about spaces in > > > filenames. I was told not to use this method, but to use the content > > > provider, but that only gets called if I move away from the file: uri > > > to the content: uri... but using a content provider, the share/send > > > seems to be expecting some kind of database implementation. > > > > There is no expectation of a database. > > > > Even though ContentProviders are often backed up by SQL databases, the > > abstraction is flexible enough to allow for non-database data (as is the > > case for your application). > > > > > Should I be looking for the file-specific uri in query() (those that > > > end with .png), and if that hits, then create and return a cursor that > > > contains the needed columns, fn, _data? > > > > Remember that these URIs originate from your own code, and are opaque to > > all other applications. > > > > There is really no need to be cryptic (e.g. > > content://paulsapp/item/2349), you can make them more convenient for > > yourself, for example: > > > > content://paulsapp/cache/RealFileName.png > > > > Writing query() should be really simple then. > > > > Just for reference, Open Intents File Manager does something pretty > > close with its content URIs, so you are heading down a well trodden path. > > > > -- Kostya > > > > > > > > > Thanks, > > > > > Paul > > > > > On Apr 26, 11:42 am, Kostya Vasilyev<[email protected]> wrote: > > >> > Right. > > > > >> > Any sane application dealing with a content:// URI will want to > know the > > >> > data item's title and size (at least). > > > > >> > It would do that by querying the URI for columns, defined here: > > > > >> > > http://developer.android.com/reference/android/provider/MediaStore.Me... > > > > >> > using ContentResolver, which will direct the query back to your > > >> > ContentProvider's query method. > > > > >> > Looks like the MMS application also wants to get the actual > filename > > >> > (the _data column). > > > > >> > -- Kostya > > > > >> > 26.04.2011 19:29, Paul пишет: > > > > >>> > > That did it when it comes to my own call to: > > > > >>> > > getContentResolver().openFileDescriptor(validUri, "r"); > > > > >>> > > It is now calling openAssetFile() in my content provider. > However, in > > >>> > > the usage of the send functionality with the content://... uri: > > > > >>> > > Intent share = new Intent(Intent.ACTION_SEND); > > >>> > > share.setType(StylePad.DEFAULT_MIME_PNG); > > >>> > > share.putExtra(Intent.EXTRA_STREAM, validUri); > > >>> > > startActivity(Intent.createChooser(share, > > >>> > > getString(R.string.activity_title_share))); > > > > >>> > > I am now getting a IllegalArgumentException thrown, and my > openFile/ > > >>> > > openAssetFile never gets called (the Exception is hitting > before it > > >>> > > would get there I guess). Here is the Exception: > > > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): > > >>> > > java.lang.IllegalArgumentException: column '_data' does not > exist > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java: > > >>> > > 314) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > android.database.CursorWrapper.getColumnIndexOrThrow(CursorWrapper.java: > > >>> > > 99) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > com.android.mms.ui.UriImage.initFromContentUri(UriImage.java:160) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > com.android.mms.ui.UriImage.<init>(UriImage.java:90) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > com.android.mms.ui.MMSMessage.addImage(MMSMessage.java:1076) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > com.android.mms.ui.ConversationList.addMedia(ConversationList.java: > > >>> > > 7095) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > com.android.mms.ui.ConversationList.addAttachment(ConversationList.java: > > >>> > > 8370) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > com.android.mms.ui.ConversationList.handleIntent(ConversationList.java: > > >>> > > 1860) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > com.android.mms.ui.ConversationList.access$2800(ConversationList.java: > > >>> > > 180) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > com.android.mms.ui.ConversationList > > >>> > > > $ThreadListQueryHandler.onQueryComplete(ConversationList.java:2999) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > > android.content.AsyncQueryHandler.handleMessage(AsyncQueryHandler.java: > > >>> > > 344) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > android.os.Handler.dispatchMessage(Handler.java:99) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > android.os.Looper.loop(Looper.java:123) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > android.app.ActivityThread.main(ActivityThread.java:4627) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > java.lang.reflect.Method.invokeNative(Native Method) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > java.lang.reflect.Method.invoke(Method.java:521) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > com.android.internal.os.ZygoteInit > > >>> > > $MethodAndArgsCaller.run(ZygoteInit.java:871) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629) > > >>> > > 04-26 11:12:54.322: ERROR/AndroidRuntime(12440): at > > >>> > > dalvik.system.NativeStart.main(Native Method) > > > > >>> > > Looking at the source: > > >>> > > > http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.... > > > > >>> > > So the Send functionality is querying my Provider's query() > method, > > >>> > > which I can see, but it is looking for two columns that I > simply don't > > >>> > > have, Part.FILENAME (column fn) and then if not found, column > > >>> > > Part._DATA (column _data). > > > > >>> > > Any ideas how to respond to this? > > > > -- > > Kostya Vasilyev --http://kmansoft.wordpress.com > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" 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-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] 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 [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-developers?hl=en

