android


What is the purpose of a custom category or action?


I'm reading Beginning Android Application Development by Wei-Mung Lee. I'm confused about custom actions and categories.
Here's some code from one example. The action is a package name. The only time that it's ever referred to ever again is in
Intent i = new Intent( "net.learn2develop.MyBrowser" );
to start an activity. How is it that this action, which is basically a package name, can know to start an activity? Just because it's inside the activity tag?
The same thing with the category tag (different example):
<intent-filter>
<action android:name=”android.intent.action.VIEW” />
<action android:name=”net.learn2develop.MyBrowser” />
<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”net.learn2develop.Apps” />
<data android:scheme=”http” />
</intent-filter>
net.learn2develop.Apps is a name that was made up by the author. It really has no meaning, right? What purpose does it serve?
How is it that this action, which is basically a package name, can know to start an activity?
Because the <intent-filter> of the activity advertised that it can be started via that action string. BTW, just because it's written like a package name does not mean it has to be a package name (e.g., android.intent.action.VIEW is not a package). The package naming convention is to prevent accidental collisions with other installed apps.
It really has no meaning, right?
Well, it probably meant something to the author, though I couldn't tell you what, exactly.
What purpose does it serve?
In normal Android development, you would not create a custom category. I cannot recall ever seeing one, and I've been doing Android development for quite a while now.
Categories are usually used to distinguish different use cases. For example, perhaps the second-most-popular category besides DEFAULT is BROWSABLE. Activities supporting the VIEW action in the BROWSABLE category become eligible to be used from links in a Web browser. So, if I had an activity for VIEW/BROWSABLE and a MIME type of application/pdf, and the user clicked on a link to a PDF file in a browser, I could be chosen to view the PDF. However, if I lacked BROWSABLE as a category, then I would not be eligible for that link. Usually, an activity would only advertise BROWSABLE if it could retrieve an HTTP URL.
Off the top of my head, I cannot think of a scenario where I'd use a custom category, though.
What purpose does it serve?
For the vast majority of cases, there is little or no use for setting the category. However, if you wish to export a BroadcastReceiver (ie make it possible for other apps to broadcast to it), but you wish to limit which apps can actually trigger the receiver, one was is to use a private category known only to those apps.
Obviously this must be done programatically:
intent.addCategory('com.super.dooper.thing.my_sectrect_category')
If you put it in the manifest, you are declaring it, and it ceases to be quite so private.

Related Links

when i click list button it not responding
How detect when the phone enters into a nfc field using card emulation
Blowfish algorithm openssl Android Native
Android : Copy folder from assets to /data/data on rooted devices
Call to Fragment Life Cycle methods increases with every Orientation change
App with Google Maps doesn't build in Android Studio
MVC4 jQueryMobile SQL phoneGap from responsive to app
full screen layout in Scroll View
How not to repeat a mathematical operation
MVVMCross: Binding Two Way doesn't update viewmodel
How to Handle Navigation between Dependent Activities
Full screen android layout with rows having the same height
-webkit-appearance: caret; removes input border from android and windows browsers
Run specific code during app update
Print from your Android application with Bluetooth Printer
how to wrap code of android app to ios using the phonegap?

Categories

HOME
uml
cygwin
toolbox
saml-2.0
gradient
grafana
polling
android-json
flume
sendgrid-api-v3
32bit-64bit
jquery-ui-sortable
text-mining
spring-social
selenium-ide
enterprise-architect
qsqlquery
jersey-1.0
imessage
sencha-touch
selinux
symbols
ag
jquery-ias
imageresizer
angularjs-components
paperjs
anki
keras-layer
joomla2.5
reverse
sql-delete
zoomify
modernizr
numberpicker
attributeerror
datacachefactory
escpos
movilizer
chronicle-map
bindingnavigator
flask-login
uiimage
fwrite
ovf
activeperl
mongotemplate
remedy
page-replacement
android-testing
dt
d3-force-directed
baidu
bootstrap-tags-input
latin
adafruit
jquery-jscrollpane
avspeechsynthesizer
jtwig
qiime
deep
httpruntime.cache
phpgrid
atan2
directdraw
file-move
page.js
binomial-theorem
branch-and-bound
jsvc
matlab-deployment
jquery-forms-plugin
bcache
machine-instruction
cancellation
live555
synapse
gtm-oauth2
jeromq
modular
sqlclr
robotlegs
panda3d
uimanageddocument
lambdaj
floating-point-exceptions
luabind
procedures
silent
vs-android
addchild
pagemethods
escrow
fdf
blind

Resources

Encrypt Message