GAMES PC DOWNLOAD FREE FULL

GAME

Android Intents: Part3: Intent Filters

 

Android components like activities can also serve implicit intents. but to do so they have to filter all implicit intents in order to serve only the intents they desire to serve. this is done using intent filters.

Suppose you want to create an activity that acts as the default dialer activity. You must associate an intent filter with this activity in order to that this activity serve the dial intents only.

Let's demonstrate a simple example which is creating an application with one activity that we want to make it a dialer activity.

Create a new android project, create an activity and name it Dialer.

In the AndroidManifest.xml file of this application add the following to the Dialer activity:
<intent-filter android:priority="100" >
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel"/>
</intent-filter>
to become:
<activity android:name=".Dialer"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:priority="100" >
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel"/>
</intent-filter>
</activity>
Now what we have done is adding an intent filter to that activity. this intent filter has the following properties:
  1. Action: the type of implicit intents that this activity responds to. in our case it is the dial action. higher numbers represent higher priority.
  2. Priority: about the priority of that activity over other activities that respond to the same type of intents.
  3. Category: Implicit intents have built-in categories. in order that an implicit intent be captured by our activity, the implicit intent category must match our activity category.
  4. Data: adds data specification scheme to the intent filter.
So if any other application has the following module to launch the dialer:
Intent in=new Intent(Intent.ACTION_DIAL, Uri.parse("tel:000"));
startActivity(in);
The user will see the following dialog offering him/her the choice between the default dialer and our custom dialer.
Android Intents: Part3: Intent Filters 4.5 5 Thanh Nguyen Android components like activities can also serve implicit intents. but to do so they have to filter all implicit intents in order to serve ...


No comments:

Post a Comment

NEW GAME

Powered by Blogger.

Labels

Quotes

1. Những cô gái giống như những tên miền Internet, những tên đẹp mà ta thích đã có chủ nhân rồi!


Popular Posts