I'm using content URI's to link content (more like launch a specific activity) in an app and other apps that I've developed but the problem is anytime one application is selected from the android launcher the rest of the URI's keep opening using that singular app
I'm building the uri links using the Linkify class. Below shows the URI's
Pattern inlinkMatcher = Pattern.compile("\\(click[^()]*\\)|\\(you can[^()]*\\)|\\(check here [^()]*\\)");
String inLinkURL = "content://com.n4labs.sexed.providers/hgcontent/";
Pattern inlinkMatcher2 = Pattern.compile("\\(click here to find [^()]*\\)");
Pattern inlinkMatcher3 = Pattern.compile("\\(learn more [^()]*\\)|\\(talk to [^()]*\\)");
boolean yfsinstalled = appInstalledOrNot("com.n4labs.yfs");
String inLinkURL2 = "http://market.android.com/details/?id=com.n4labs.yfs";
if(yfsinstalled)
inLinkURL2 = "content://com.n4labs.yfs.providers/centersearch/";
boolean divainstalled = appInstalledOrNot("com.n4labs.diva");
String inLinkURL3 = "http://market.android.com/details/?id=com.n4labs.diva";
if(divainstalled)
inLinkURL3 = "content://com.n4labs.diva.providers/learn/";
And the calls to Linkify
if(yfsinstalled){
Linkify.addLinks(itemController3.paragraphtext, inlinkMatcher2, inLinkURL2);
}
else
{
Linkify.addLinks(itemController3.paragraphtext, inlinkMatcher2, inLinkURL2, null, mentionFilter);
}
if(divainstalled){
Linkify.addLinks(itemController3.paragraphtext, inlinkMatcher3, inLinkURL3);
}
else
{
Linkify.addLinks(itemController3.paragraphtext, inlinkMatcher3, inLinkURL3, null, mentionFilter);
}
Linkify.addLinks(itemController3.paragraphtext, inlinkMatcher, inLinkURL);
The provider in each app has the appropriate authority and is exported as such
<provider
android:name="com.n4labs.diva.providers.HealthGuideContentProvider"
android:authorities="com.n4labs.diva.providers"
android:exported="true">
</provider>
How can I ensure that each URI opens in the appropriate application automatically, or at least the option is displayed to the user every-time.
I hope I was clear enough.
Anyone?
Thanks.
Each of your
ContentProviders
is reporting that the MIME type associated with thoseUri
values istext/plain
. This is a very common MIME type, one normally associated with standard text files.When the user clicks on a link for any of those
Uri
values, Android will construct anACTION_VIEW
Intent
, for a MIME type oftext/plain
, and attempt to start an activity for that, such as a text editor.The key now is: what do these
ContentProviders
actually deliver, as content, for thoseUri
values? In other words, if I were to callopenInputStream()
on aContentResolver
, passing in one of thoseUri
values, what data do I get back in the stream?There are five main possibilities that I see:
They legitimately return plain text, and you really do want an ordinary text editor to be an option for the user to work with that text. In that case, your setup is fine. Bear in mind that the user might elect to click the "always" option for handling these
Uri
values and therefore may not necessarily want to be presented with a choice of activities each time. After all, in this scenario, all three of your activities can work with all three of your providers, and regular text editors can also work with these providers.They legitimately return plain text, but you really do not want anything other than your activities handling those
Uri
values. In that case, get rid of theContentProviders
, get rid ofLinkify
, and add your ownClickableSpans
to the text to directly start activities of your choosing.They do not return plain text, but instead return data in some other format, and you are willing for third-party apps to be able to work with that content. In that case, change the MIME type (in the provider and in the associated
<intent-filter>
) to the correct value, instead oftext/plain
. This may involve you creating your own custom "vendor" MIME type, if your data does not match any standard data format.The
openInputStream()
call would crash, because you have a buggyContentProvider
that is not actually serving data for theseUri
values. In that case, fix theContentProvider
, then run through this list of possibilities again. Since you are exporting this provider, you need to actually implement it properly.The
openInputStream()
call would crash, or the providers would return something other than plain text, but you are not intending on anybody actually using this content other than yourself. In that case, get rid of theContentProvider
, get rid ofLinkify
, and add your ownClickableSpans
to the text to directly start activities of your choosing.My guess is that your case is #2 or #5.