Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between declaring an intent-filter in an activity vs. a receiver?

I would like my application to be registered a handler for phone calls via the "Complete action using..." dialog. I've found that it works if I use the following syntax in my manifest:

   <activity android:name="my.class">
       <intent-filter>
          <action android:name="android.intent.action.CALL_PRIVILEGED" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:scheme="tel" />
       </intent-filter>
   </activity>

but if I register it as a broadcast receiver, my app doesn't show up in the "Complete action using..." dialog.

   <receiver android:name="my.class">
       <intent-filter>
          <action android:name="android.intent.action.CALL_PRIVILEGED" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:scheme="tel" />
       </intent-filter>
   </receiver>

What's the difference between the two apart from the type of class that's going to be called once an Intent matches the filter?

like image 401
bmajz Avatar asked Jun 02 '12 01:06

bmajz


People also ask

What is the difference between a broadcast receiver and an intent filter?

An IntentFilter specifies the types of intents to which an activity, service, or broadcast receiver can respond to by declaring the capabilities of a component. BroadcastReceiver does not allows an app to receive video streams from live media sources.

What's the difference between intent and intent filters?

An intent is an object that can hold the os or other app activity and its data in uri form.It is started using startActivity(intent-obj).. \n whereas IntentFilter can fetch activity information on os or other app activities.

What is the difference between activity and intent?

Activity is a UI component which you see on your screen. An Intent is a message object which is used to request an action from the same/different app component.

What is the purpose of the intent filter?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.


1 Answers

Difference is clear: the first one will try to launch an Activity, while the second one will execute a BroadcastReceiver. What to use depends on what you want to achieve; use BroadcastReceiver when you want to catch some event but do not want to show anything to the user.

like image 106
Cristian Avatar answered Sep 18 '22 05:09

Cristian