android - intent action namespace - android

Android's intent documentation states that :
action must be in a namespace because Intents are used globally in the system
Does this namespace concept just imply that if I don't use, for e.g., my app's package name as a prefix for a custom action name, then it may conflict with the action name for a different app, so when some app is using intent, it may start the wrong component because of my name conflict. Is there any more detail that needs to be worried about when it comes to namespace in intents ?

Does this namespace concept just imply that if I don't use, for e.g., my app's package name as a prefix for a custom action name, then it may conflict with the action name for a different app, so when some app is using intent, it may start the wrong component because of my name conflict.
More or less.
Is there any more detail that needs to be worried about when it comes to namespace in intents ?
It is unlikely that creating a custom action is the right solution for whatever problem that you are solve. One use case for it is if you are going to try to convince third-party developers to specifically invoke one of your activities, perhaps as part of an SDK that you are creating for such developers. This is well within reason, just unlikely. Another use case would be if you have a suite of apps that you were trying to inter-link at specific spots. This is somewhat more probable, but it becomes a bit of a problem to do well -- by default, any app in the system will be able to start that activity if they so chose, and securing that can get tricky.
Note that you neither want nor need an action string of any sort for activities that are private to your app. That's because you neither want nor need an <intent-filter> for activities that are private to your app. Just use explicit Intents to invoke such activities.

Related

Public Intents for Other Applications to Use

I am creating an app with a service, and I would like other apps to be able to interact with and extend it. I can think of two scenarios:
another app wants to interact with the service
someone develops a better version of the service that they would
like my app to use instead of my built-in service
Most of the things that I have read about actions say that you should name your action something like com.mycompany.appname.CUSTOM_ACTION. However, I do not think I should put the actions in my own namespace since other developers might want their apps to be able to receive them. Instead, I think they should give them a more public name, like intent.action.CUSTOM_ACTION.
Is there a convention for naming public actions? Is it ok that I name my actions like intent.action.CUSTOM_ACTION, or is that a no-no?
It's bad idea to give it generic names. It comes with your app and therefore you should stick to com.mycompany.appname.CUSTOM_ACTION namespace
openintents.org is a website that appears to allow developers to register intents that they want other applications to use.

Why do the Android docs say intent extras need package prefix

According to the Android docs Intent extra name must have a package prefix. I've been using Intent extra names without prefixes for a long time and it seems like there is no chance of collision since what really matters is the Intent action being unique. So are the docs just wrong or am I missing something?
The docs for putExtra say:
Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".
I believe the Android docs recommend using fully-qualified extras is to handle an uncommon edge case. The edge case is when you are:
Writing an Activity that can be started using a public Intent action such as Intent.ACTION_VIEW
AND
For your own usage you want to be able to pass custom extras to the Activity described above without interfering with another Activity that is doing the exact same thing and might have extras with the same name but different meanings or format
Phew, it all sounds very unlikely. If you aren't handling public Intent actions then it still seems as though there is no need to fully-qualify your extras, but I guess it doesn't hurt to do it all the time if you are the paranoid type.
Intents can be passed on to other apps and the system it self, so courtesy is to use a package namespace.
From the official tutorials:
It's a good practice to define keys for intent extras with your app's
package name as a prefix. This ensures that the keys are unique, in
case your app interacts with other apps.
Unless your app interacts with other apps, or you foresee that it might need to do so in the future, you can safely omit package prefixes in your extras.

android - is it possible to use private intents instead of global ones?

background:
i've noticed that for regular activities within, it is possible for any application to open the activities of my app .
question:
is it possible to allow only my own app (or apps , or package) to send and receive intents inside the same scope , so that other application won't be able to receive them or interfere with the flow of the app?
example:
suppose i have a broadcastReceiver that listens to some kind of intent , but this intent is only meant to be used by another service/activity that resides either inside my app , or inside another app that i've created , but i don't want others to be able to use this intent.
please help me.
setPackage()
Set an explicit application package name that limits the components this Intent will resolve to. If left to the default value of null, all components in all applications will considered. If non-null, the Intent can only match the components in the given application package.
or you can use setSelector() , but not both.
suppose i have a broadcastReceiver that listens to some kind of intent , but this intent is only meant to be used by another service/activity that resides either inside my app , or inside another app that i've created , but i don't want others to be able to use this intent.
In addition to Reno's fine answer, for your specific requirement quoted above, use LocalBroadcastManager. Not only do you get the security you seek, but it is more efficient. LocalBroadcastManager is available in the Android Support package and AFAIK should work going back to Android 1.6. Here is a sample project using LocalBroadcastManager.

How can i know supported intents of the 3rd party app

I've built an app called xLancer (https://market.android.com/details?id=kz.jay.xlancer.activity) that retrieves job listings from Elance. Now i want to implement a feature that would remind me to bid on a project at a later time. Instead of reinventing the wheel i want to launch any external TODO/Task manager app. But now i am stuck, i don't know which URI or action should be specified, so far i've only used intents to call my internal activities by specifying class name explicitly.
So the question is: how can i know which URI/action should be specified?
Look here, I didn't see any Todo/Task intents there though....

Android: Proper way to reuse my app's activities?

What's the proper way for other people to reuse my Activities? Should they hard code the intent actions in their app or is it customary to provide them with a jar file enumerating my app's intent actions? Is there a less tightly-coupled way to lookup the intent actions?
First of all, take a look at openintents.org and see if there's any match to what your activity does.
Secondly, documentation is always a good idea.
Having the intent details hardcoded in their applications should work just fine. After all, the intents are part of your public interface and shouldn't change.
Your applications manifest should announce what sorts of things your activity can handle, via intent-filters. Outside users can read the manifest to determine what actions you support, and invoke them via action intents.
See intents and intent filters for more details.

Categories

Resources