Naming Android mime-types/Uris:
The sample notepad application uses:
"vnd.android.cursor.dir/vnd.google.note"
"vnd.android.cursor.item/vnd.google.note"
Let's say I want create my own application with three datatypes that should be stored in the database, how should I name my uris?
Should all content uris start with vnd.android.cursor.dir and vnd.android.cursor.item before the slash?
It doesn't really matter. AFAIK there is no naming convention for it. Use whatever you like, just make them UNIQUE.
Mime Types:
You should always make your MIME types start with vnd.android.cursor.item for a single record, or vnd.android.cursor.dir/ for multiple items, followed by your custom vender specific name definition:
vnd.android.cursor.dir/vnd.custom.name
As recommended by the Android documentation found here
Related
I just realized by performing a replace all in my strings.xml file today that we are not allowed to put https in the xmlns:tools attribute for the Android schema.
Why is that?
Namespaces conventionally take the form of URIs because this is a convenient way of ensuring uniqueness. But really, they are just character strings. The "http://" that you find at the start of many namespace names doesn't imply that the HTTP protocol is in use, it's just a conventional way of forming unique names. Because it's just a character string, something looking for "http://www.w3.org/xhtml", say, is not going to recognize "https://www.w3.org/xhtml", because that's a different name and therefore a different namespace.
(Historically, when namespaces were first introduced, some people wanted them to be URIs that actually referred to something on the network; and some organisations including W3C do try to ensure that if you put the namespace URI in the address bar of your browser, you get something meaningful back. But that's a secondary role. Primarily, a namespace name is just a string.)
We usually have this naming convention - com.something.something in Android.
Is it valid if we do not use the com. part and just keep it like something.something (provided that something.something is unique)
https://stackoverflow.com/a/4620116/6441416
I don't think it would be valid but anyway.
Look through his answer. Hope this helps.
Usually Android follows the naming convention as Java, I think it doesn't make any difference if it is a unique application id..
As per Android Developers
If you have a company domain www.example.com
Than you should use:
com.example.region.projectname
If you own a domain name like example.co.uk than it should be:
uk.co.example.region.projectname
But though many application doesn't have any prefix of domain and also they are running on Play Store for example
The proper way to naming an apk is starting with com.somthing.But not mandatory for google play store.This format comes to make an app id is unique.So you can give your app id anything you want to.
What means vnd.android (vnd.android.cursor.dir)?
Where can I find full list and description about this types?
I found this page http://en.wikipedia.org/wiki/Internet_media_type but this is not a complete list. Please give any link of full media type list.
Advance Thanks
The vnd. prefix on a MIME type is a "vendor prefix", meaning that it is not an official IETF MIME type.
vnd.android.cursor.dir is part of a faux MIME type used for database-style ContentProviders in Android, specifically for Uri values that map to what logically would be considered "tables" or "views" (collections of content). For example, the AOSP Contacts application has activities that will respond to a MIME type of vnd.android.cursor.dir/contact. You can find various other uses of vnd.android by filling that into the search field in the Android developer documentation.
Where can I find full list and description about this types?
There is none that I am aware of. Vendor-prefixed MIME types can be used or defined by anyone.
After several searches online, I couldn't find a place that could tell me every existent MIME type for different types of media in Android applications.
Here are the ones I know that exist and work:
For Text
"text/plain"
For Image
"image/jpeg"
"image/bmp"
"image/gif"
"image/jpg"
"image/png"
For Video
"video/wav"
"video/mp4"
These are the ones I have and know that work, I am lacking several for video and sound type files. Does anyone know a place where every Android MIME type is described or have you guys ever used another MIME type for these different types of media?
EDIT:
I am using this in an application that monitors SMS and MMS, and in the MMS, the type manages the content inside it. The code I have runs for every version above 8.
I did some search these days.
maybe you shoud read these links.
MediaStore supported MIME type is here: http://androidxref.com/4.4.4_r1/xref/frameworks/base/media/java/android/media/MediaFile.java#174
And there is also a API URLConnection.getFileNameMap()
And its inner side is here: http://androidxref.com/4.4.4_r1/xref/libcore/luni/src/main/java/libcore/net/MimeUtils.java
I couldn't find a place that could tell me every existent mime type for different types of media in android applications
There are over a million applications on the Play Store, plus others elsewhere (e.g., pre-installed on devices, Amazon AppStore for Android). A given device will have some combination of these apps. A given user will have access to some subset of the apps on the device, if the user is running in an Android 4.3+ restricted profile on a tablet.
Hence, there is no way to know, at compile time, what MIME types a given Android device can support for things like ACTION_VIEW activity requests. The OS itself supports no such MIME types -- they are all provided by applications.
Here are the ones I know that exist and work:
Some devices may have apps pre-installed that support those MIME types. text/plain is the least likely of your set to be supported "out of the box".
You can use existing mapping in Android (java version)
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.toLowerCase());
I know I'm late to the party, but I found a full list of mime types here:
https://android.googlesource.com/platform/external/mime-support/+/9817b71a54a2ee8b691c1dfa937c0f9b16b3473c/mime.types
Which MIME types does Android support out of the box?
Since that's your immediate question, let's answer that first (though it's not exactly the right question for your MMS usecase).
To know the MIME types supported by Android itself (not considering additional apps), you can use this process:
Consult the list Supported media formats from the official Android documentation.
For each media format and each of its possible container formats, find the associated MIME types from the official IANA Media Types list.
Since there are some unregistered MIME types in use in practice, including by Android, additionally consult the list of MIME types known to the Android platform to convert the supported media formats. For example, the Matroska video container format (.mkv files) appears only in that list, not in the IANA list.
Which MIME types might you encounter in MMS?
tell me every existent mime type for different types of media in android applications. […] I am using this in an application that monitors SMS and MMS and in the MMS type manages the content inside it.
For your case, the MMS standard will tell you what MIME types can be used for its content. And it seems that, like e-mail, MMS does not restrict what MIME types its content can be. For example, one supplier of MMS solutions tells that it will simply pass content with unknown MIME types to the network carrier:
If the format is not listed below that means it still gets accepted on the API, but […] it may get delivered to the carrier or may not depending on the size of the content. (source)
Since applications can define their own MIME types, including types starting with prs. and x. that cannot be registered at IANA, you cannot know beforehand which MIME types you will encounter.
So for practical purposes, it is the safest approach if your application can deal with all MIME types supported by the Android platform by default – see above for the list. And then handle everything else (added by apps) in a generic manner.
I'm trying to define two different file extension mappings and two different mime-type IntentFilters in my manifest file but I can't seem to get them all to work; one works and others don't, etc.
How does one define multiple pathPatterns in the manifest? Should/can all mime-types and pathPatterns be defined in a single IntentFilter? Should they be different filters? I can't find any examples that show multiple, distinct mappings.
I have settled on grouping similar definitions together into distinct Intent Filters. For example, grouping the same pathPattern with different schemes (http, https, file) into one Intent Filter and defining another Intent Filter for a different pathPattern with the same set of schemes. I haven't encountered any specific guidelines or documentation about this so I've gone with my own aesthetic preference.
The source of my difficulties appears to have been the limited functionality of pathPattern. After seeing the .* explanation in the documentation, I had hoped pathPattern would accept other regex syntax but in practice it appears .* really is the only option for any kind of flexibility.
Also, the often cited method for defining a file-type filter has a bug/limitation that I have not been able to find a way around or an explanation for: pathPattern=".*\\.xyz" will work for "MyFile.xyz" but NOT for "My.File.xyz". I have since posted another question about this specific issue.