Android: the exact location of content:\\ - android

I'm looking for the path mentioned as below:
private static final String STOCK_BOOKMARKS_CONTENT = "content://browser/bookmarks";
private static final String CHROME_BOOKMARKS_CONTENT = "content://com.android.chrome.browser/bookmarks";
Where is the exact physical location of these paths on my Android mobile phone?

Content URIs are not (necessarily) file system paths. They are a representation defined by the content providers to serve data to whoever requests it without revealing the actual source of data, in a way.
The Content URI's are generally in the following form :
content://authority/path/id
Where
content - the first part (here content) is the scheme of the URI. It could be anything like file for File Uri's.
authority - The name of the content provider , i.e. the content provider uses this part to identify content uri's meant for them and not for some other content provider.
path & id - these are defined by the content providers to (generally) identify the exact location of data in their data store (local database, some rest api etc)
Interestingly, Content providers provide a way to get a hold of an InputStream for the content represented by a ContentURI - using getContentResolver().openInputStream(uri)
Related
http://developer.android.com/reference/android/content/ContentUris.html
Android: Getting a file URI from a content URI?

It depends of Device and system, purpose of "content" is abstraction of files location

Related

Accessing content provider

I would like to access the content provider using URI, which is of the following form.
sUriMatcher.addURI("org.abcd.providers.contentprovider", "bookmarks", 1)
So, can I access it using the URI, "content://org.abcd.providers.contentprovider/bookmarks" ? What does the value "1" mean? How do I query the provider of this type, Thanks in advance.
The "1" is used internally in the ContentProvider. Its used to associate an URI with an number. Handy for using in a switch statement.
Why not using String matching? Well, an URI might have variable parts. For example "content://my.provider/bank/customer/2". The 2 is the Id of the customer. Or "content://my.provider/location/42/name". The variable part here is the 42. String matching goes out of control here. The UriMatcher on the other hand is able to match example 1 with addURI("my.provider", "bank/customer/#", 1) and example 2 with addURI("my.provider", "location/#/name",2). When we ask a configured UriMatcher to match a URI it returns the number associated with the matching URI.
But we are going out of track here. The number is not relevant to you as a consumer. You can query the provider with the context method 'getContentResilver().query(content://org.abcd.providers.contentprovider/bookmarks, /*other args */)'. See the documentation for more infos.
But you can only talk to the provider if its exported (nothing you can do about it) or it requires permissions that your application has. This includes no permissions at all.

Android - How to list files inside a folder with a content provider

I'm developing an application to read files through a content provider defined in another app (say app B).
Now, I'm able to read a specific file from my app (app A) using:
[...]
InputStream content = getContentResolver().openInputStream(content://.../path_of_the_folder/file_name.txt);
BufferedReader reader1 = new BufferedReader(new InputStreamReader(content));
String linetext;
while ((linetext = reader1.readLine()) != null) { //printout
[...]
but how can I list all files stored in the folder it self? I'm trying to use the "list" method defined in the class File, but how can I convert what I get from openInputStream to a File object?
Thank you very much all
The ContentProvider basic protocol does not support browsing of directory structures this way.
If you happen to be the author of both apps, you are welcome to invent your own mechanism for this, such as:
use query() on some modified version of your folder's Uri to have it return a Cursor representing the folder's contents, or
use call() and have it return a Bundle that contains a list of child folder Uri values and a list of child document Uri values, or
stream back some JSON or XML or something as the "content" of a folder, where the JSON or XML describes the contents of the folder

Is it possible to copy&paste image data to the clipboard, like on desktop OSs?

On desktop OSs, in image-editing apps, you can copy a part of the image and then go to another app and paste it.
Is it also possible and officially supported on Android?
If so, what are the capabilities of such a feature? is there a limit to the number of pixels, for example, that can be copied?
All I've found is that those are the types of data (link here):
Text - A text string. You put the string directly into the clip object,
which you then put onto the clipboard. To paste the string, you get
the clip object from the clipboard and copy the string to into your
application's storage.
URI - A Uri object representing any form of URI. This is primarily
for copying complex data from a content provider. To copy data, you
put a Uri object into a clip object and put the clip object onto the
clipboard. To paste the data, you get the clip object, get the Uri
object, resolve it to a data source such as a content provider, and
copy the data from the source into your application's storage.
Intent - An Intent. This supports copying application shortcuts. To
copy data, you create an Intent, put it into a clip object, and put
the clip object onto the clipboard. To paste the data, you get the
clip object and then copy the Intent object into your application's
memory area.
Not easily. There is no direct way to paste image data. You may be able to do it like this though:
1)Create a clip with a URI. You'll need to define a URI to that part of the photo
2)Write a content provider which provides an image MIME type.
3)Have the content provider pass along the data you wanted to paste when the URI from part 1 is requested.
It will obviously not work in all apps, as the paster needs to be able to understand and expect the image MIME type for a clip data URI. Most apps won't would be my guess.

What should implementations for #getType() and #getStreamTypes() in content provider look like when sharing all types of files

I have a file system management app, and I am sharing all types of files with external 3rd party applications using a content provider.
My question is:
What should implementations for #getType() and #getStreamTypes() in content provider look like?
Thanks for all the responses.
See docs for ContentProvider
getType (Uri uri)
Implement this to handle requests for the MIME type of the data at the given URI. The returned MIME type should start with vnd.android.cursor.item for a single record, or vnd.android.cursor.dir/ for multiple items.
getStreamTypes (Uri uri, String mimeTypeFilter)
Called by a client to determine the types of data streams that this content provider supports for the given URI. The default implementation returns null, meaning no types. If your content provider stores data of a particular type, return that MIME type if it matches the given mimeTypeFilter. If it can perform type conversions, return an array of all supported MIME types that match mimeTypeFilter.

What is the mimeType attribute in <data> used for?

I really can’t get the meaning of mimeType. I know that it exists so that the getType method in ContentProvider knows what to match with it. But I’m still not sure what it means or how it’s used.
Any ContentProvider usually defines the type of data it handles (e.g. NotePadProvider handles a Notes data type defined in an inner class of NotePad). A MIME type is just a standardized way to define that data type by giving it a unique name. This allows the data type to be communicated to code that works with a ContentProvider in a standardized way.
It also helps a ContentProvider that handles several different types of data to keep things organized, e.g. a RailwayContentProvider might handle trains, stations and tickets and can use the MIME type to tell each one apart.
Why MIME types?
The use of MIME types is a natural consequence when you think about how a ContentProvider is accessed through URIs, i.e. something like an URL on the Internet. Just like on the Internet there are MIME types like text/html for web pages and image/jpeg for .jpg images, Android wants you to define a custom MIME type for any data type your ContentProvider handles.
An example custom MIME type
In the NotePad (linked above) class of the NotePad example project, you'll find:
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.note";
This field defines a custom MIME type (recognizable by the type/subtype pattern).
Android suggests you use vnd.android.cursor.dir/... as the first part for any kind of "directory listing" (multiple items) and vnd.android.cursor.item/... as the first part for any kind of single item.
For the subtype, it's again suggested to start it with vnd. and then add something like your reverse domain name/package name, e.g. vnd.android.cursor.item/vnd.com.mydomain.myapp.mydata
To avoid all those vnd... strings in your code, there's also some constants in ContentResolver like CURSOR_DIR_BASE_TYPE and CURSOR_ITEM_BASE_TYPE.
Mimetype Multipurpose Internet Mail Extensions is tell you the description of the content
Text in character sets other than ASCII
Non-text attachments
Message bodies with multiple parts
Header information in non-ASCII character sets
and also whether is it Pdf/epub/html/text etc
If you mean mime type its to tell the receiving entity how to interpret a file. Just like you see .txt and know a file is a text file. This way you can serve a file with .anyExtension and have the browser still know it is a .txt

Categories

Resources