SlideShare uma empresa Scribd logo
1 de 20
Using Intents in Android
This article describes how to use intents in Android. It is based on Eclipse 3.7, Java 1.6 and Android 2.3.3 (Gingerbread).
Tabl eof Contents
1. Android Intents
1.1. Overview
1.2. Implicit vrsExplicit Intents
1.3. Getting theIntent datain the called Activity
1.4. Intent Filter
1.5. Intentsas event triggers
1.6. Starting Activitiesand Sub-Activities
1.7. Android Basics
2. Implicit Intents- Opening an URL
3. Explicit intentsand data transfer betweenactivities
4. Registering via Intentfilter
5. Notification Manager
5.1. Notification Manager
5.2. Example
6. Finding out ifan intent isavailable
7. Thankyou
8. Questionsand Discussion
9. Links and Literature
9.1. Source Code
9.2. Android Resources
9.3. vogellaResources
1. Android Intents
1.1. Overview
Objects of type "android.content.Intent"are used to send asynchronous messages within your application or between applications. Intents allow
to send or receive datafrom and to other activities or services. They also allow to broadcast that a certain event has occurred.
Intents are a powerful concept as they allow the creation of loosely coupled applications. Intents can be u sed to communicate between any
installed application component on the device.
An Intent object can contain information for the receiving component. For example ifyour application calls via an Intent a browser it maysend
the URL to the browser component. An Intent also contain information for the Android system so that the Android system can determine which
com ponent should handle the request.
1.2. Implicit vrsExplicit Intents
Android su pports explicit intents and implicit intents. Explicit intent names the component, e.g. the Java class which should be called.
Im plicit intents asked the system to perform a service w ithout tellingthe system whichJava class should do this service. In constructing an
im plicit Intent you specify the action which should be performed and optionally an URI whichshould be used for this action. For example you
cou ld tell the system that you want to view (action) a webpage (URI). By startingan intent for this data the system would try to find an
application which is registered for thisevent, e.g. a browwer. You canadd more datato the Intent by adding "extras"to the Intent. These are
key/value pairs.
1.3. Getting the Intent data in the called Activity
To get the Intent information in the called Activity u se the method getIntent(). If the Activity was called via an implicit Intent you canreceive
the data and url from this Intent via getAction(), getData() and getExtras().
1.4. Intent Filter
The Android system will determine suitable applications for an implicit intentand if several applicationsexists offer the user the choice toopen
one. The determination is based on intent filters, e.g. the class "android.content.IntentFilter". Intent filters are typically defined via the
"AndroidManifest.xml"file.
To react to a certain implicit intent an application component must register itself via an IntentFilter in the "AndroidManifest.xml"to this event.
If a com ponent does not define intent filters it can only be called by explicit intents.
1.5. Intentsasevent triggers
Intents canalso be used to broadcast messages into the Android system. An Android application can registerBroadcast Receivers to these
ev ents and react accordingly. The Android system also u ses Intents to broadcast system events. Yourapplication can also register to these
sy stem events, e.g. a new email has arrived, system boot is complete or a phone call is received and react accordingly.
1.6. Starting Activitiesand Sub-Activities
To start an activity u se the method startActivity(Intent) if you do not need a returnvalue from the called activity.
If y ou need some information from the called activity u se the method startActivityForResult(). Once the called Activity is finished the method
onActivityResult() in the calling activity w ill be called. If you use startActivityForResult() then the activity which is started i s considered a "Su b-
Activity".
1.7. Android Basics
The followingassumes that you have already basic knowledge in Android development . Please check the Android development tutorial to learn
the basics.
2. Implicit Intents - Opening an URL
The followingcreatesan examle project for calling several implicit intent. The Android system is asked to display a URI and chooses the
corresponding application for the right URI. Create a new Android application "de.vogella.android.inten t.implicit"w ith the Activity
"CallIntents". Create the following view layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Call
browser" android:onClick="callIntent"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Call
Someone" android:width="100px" android:onClick="callIntent"></Button>
<Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Dial"
android:width="100px" android:onClick="callIntent"></Button>
<Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show
Map" android:width="100px" android:onClick="callIntent"></Button>
<Button android:id="@+id/Button05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Search
on Map" android:width="100px" android:onClick="callIntent"></Button>
<Button android:id="@+id/Button06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Take
picture" android:width="100px" android:onClick="callIntent"></Button>
<Button android:id="@+id/Button07" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show
contacts" android:width="100px" android:onClick="callIntent"></Button>
<Button android:id="@+id/Button08" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Edit
first contact" android:width="100px" android:onClick="callIntent"></Button>
</LinearLayout>
To be able to use certain intents you need to register then for your application. Maintain the following "AndroidManifest.xml".
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.intent.implicit"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".CallIntents"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
</manifest>
Change your activity to the following. We will start the new intent with the method startActivityForResult() which allow us t o specify a desired
resu lt code. Once the intent is finished the method onActivityResult() is called and you canperform actions based on the result of the activity.
package de.vogella.android.intent.implicit;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class CallIntents extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void callIntent(View view) {
Intent intent = null;
switch (view.getId()) {
case R.id.Button01:
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.vogella.de"));
startActivity(intent);
break;
case R.id.Button02:
intent = new Intent(Intent.ACTION_CALL,
Uri.parse("tel:(+49)12345789"));
startActivity(intent);
break;
case R.id.Button03:
intent = new Intent(Intent.ACTION_DIAL,
Uri.parse("tel:(+49)12345789"));
startActivity(intent);
break;
case R.id.Button04:
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:50.123,7.1434?z=19"));
startActivity(intent);
break;
case R.id.Button05:
intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=query"));
startActivity(intent);
break;
case R.id.Button06:
intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);
break;
case R.id.Button07:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/"));
startActivity(intent);
break;
case R.id.Button08:
intent = new Intent(Intent.ACTION_EDIT, Uri.parse("content://contacts/people/1"));
startActivity(intent);
break;
default:
break;
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == 0) {
String result = data.toURI();
Toast.makeText(this, result, Toast.LENGTH_LONG);
}
}
}
If y ou start yourapplication you should see an list of buttonsand if you press the button, different activities should be p erformed. Note that you
do not specify any specific application.
3. Explicit intents and data transfer between activities
The followingdemonstrates how you cantransfer databetween two activities. We will use explicit intents in this example and create two
activities. The first activity will call the second one via an explicit intent. This second activity will receive data from the first one via the class
"Bu ndle"which canbe retrieved via intent.getExtras().
The second activity canbe finished either via the back button on the phone or via the button. The method fin ish() is performed in this case. In
this method you cantransfer some data back to the calling activity. This is possible because we u se the method startActivity ForResult(). If you
start an activity via this method the method onActivity result is called on the callingactivity once the called activity is finshed.
Create a new Android application "de.vogella.android.intent.explicit"w ith the Activity "ActivityOne". Change the layout "main.xml"to the
follow ing.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Activity. Press button to call second activity"
android:minHeight="60dip" android:textSize="20sp"></TextView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="wrap_content"></LinearLayout>
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:onClick="onClick"
android:text="Calling an intent"></Button>
</LinearLayout>
Create the layout "second.xml".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="First value from Activity 1"></TextView>
<EditText android:text="@+id/EditText01" android:id="@+id/EditText01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Second Value from Activity one"></TextView>
<EditText android:text="@+id/EditText02" android:id="@+id/EditText02"
android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText>
</LinearLayout>
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:onClick="onClick"
android:text="Finished this activity"></Button>
</LinearLayout>
Create a new activity "ActivityTwo"via the AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.intent.explicit"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ActivityOne"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="ActivityTwo" android:name="ActivityTwo"></activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
Create the following coding for your two activities. The second activity will be called from the first one, displays the transferred dataand ifyou
select the button of the back button on the phone you send some data back tot the callingapplication.
package de.vogella.android.intent.explicit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class ActivityOne extends Activity {
private static final int REQUEST_CODE = 10;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View view) {
Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");
// Set the request code to any code you like, you can identify the
// callback via this code
startActivityForResult(i, REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
if (data.hasExtra("returnKey1")) {
Toast.makeText(this, data.getExtras().getString("returnKey1"),
Toast.LENGTH_SHORT).show();
}
}
}
}
package de.vogella.android.intent.explicit;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class ActivityTwo extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.second);
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
String value1 = extras.getString("Value1");
String value2 = extras.getString("Value2");
if (value1 != null && value2 != null) {
EditText text1 = (EditText) findViewById(R.id.EditText01);
EditText text2 = (EditText) findViewById(R.id.EditText02);
text1.setText(value1);
text2.setText(value2);
}
}
public void onClick(View view) {
finish();
}
@Override
public void finish() {
Intent data = new Intent();
data.putExtra("returnKey1", "Swinging on a star. ");
data.putExtra("returnKey2", "You could be better then you are. ");
setResult(RESULT_OK, data);
super.finish();
}
}
4. Registering via Intentfilter
You r application canalso register ifself for implicit intentsin Eclipse. For this you have to specify an intent filter for the selected event. Intent
filters are typically declared in "AndroidManifest.xml". An intent filter must specify category, action and data filters.
Lets create a small browser. Ourapplication will register itself as a browser and will display the HTML code for a giving webpage.
Create the Android project "de.vogella.android.intent.browserfilter"w ith the activity "BrowserActivitiy". Change "AndroidManifest.mf"to the
follow ing to register your application to the browser view intent. THe following also request the permission to access the Internet.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.intent.browserfilter"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".BrowserActivitiy"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Change "main.xml"to the following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"/>
</LinearLayout>
As y our activity gets called withan intent you canget the data from the intent and display it in your application.
package de.vogella.android.intent.browserfilter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
public class BrowserActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
TextView text = (TextView) findViewById(R.id.textView);
// To get the action of the intent use
System.out.println(intent.getAction());
// We current open a hard-coded URL
// To get the data the intent use the following line
//Uri data = intent.getData();
URL url;
try {
// url = new URL(data.getScheme(), data.getHost(), data.getPath());
url = new URL("http://www.vogella.de");
BufferedReader rd = new BufferedReader(new InputStreamReader(
url.openStream()));
String line = "";
while ((line = rd.readLine()) != null) {
text.append(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
If y ou call and URL you should be able to select your browser and the HTML code should be loaded into your textview.
5. Notification Manager
5.1. Notification Manager
To pu t a notification into the title barof Android you use the notification manager. The user canopen the notification bar and from the
notification another activity canget triggered.
You u se the "NotificationManager"class which canbe received from the Activity via getSystemService(). You then configure you class
"Notification"and create an intent you will call the target activity.
The followingu ses a PendingIntent whichis described in Android Services and PendingIntents .
5.2. Example
Create a new project "de.vogella.android.notificationmanager"w ith the Activity "CreateNotification". Create the following layout "result.xml".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:text="This is the result activity opened from the notification"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/textView1"></TextView>
</LinearLayout>
Change "main.xml"to the following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Create Notification" android:onClick="createNotification"
android:id="@+id/button1" android:layout_height="match_parent"
android:layout_width="match_parent"></Button>
</LinearLayout>
Create a new activity "NotificationReceiver"w ith the following coding. Don't forget to register the activity in the "Android Manfest.mf".
package de.vogella.android.notificationmanager;
import android.app.Activity;
import android.os.Bundle;
public class NotificationReceiver extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
}
}
Change the activity "CreateNotification"to the following.
package de.vogella.android.notificationmanager;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class CreateNotification extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void createNotification(View view) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"A new notification", System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(this, NotificationReceiver.class);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "This is the title",
"This is the text", activity);
notification.number += 1;
notificationManager.notify(0, notification);
}
}
Ru n your application and pressthe button. A new notification is created. If y ou select it your second activity will be displayed.
6. Finding out if an intent is available
Som etimes you want to find ifan application is available for a certain intent. This canbe done via checking the PackageManager. The following
code checks if an intent exists. You can check via this method for intent and change yourapplication behavior accordingly fo r example disable or
hide menu items. This tip is based on a blog entry from Romain Guy .
public boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> resolveInfo =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo.size() > 0) {
return true;
}
return false;
}
7. Thank you
Please help me to support thisarticle:
8. Questions and Discussion
Before posting questions, please see the vogella FAQ . If y ou have qu estions or find an error in this article please use the www.vogella.de
Google Group . I have created a short list how to create good questions w hichmight also help you.
9. Links and Literature
9.1. Source Code
Source Code of Examples
9.2. Android Resources
Android Location API and Google Maps
Android and Netw orking
Android Homepage
Android Issues / Bugs
Android Google Groups
9.3. vogella Resources
Eclipse RCP Training (German) Eclipse RCP Training with LarsVogel
Android Tutorial Introduction to Android Programming
GWT Tutorial Program in Java and compile to JavaScript and HTML
Eclipse RCP Tutorial Create native applications in Java
JUnit Tutorial Test your application
Git Tutorial Pu t everything you have under distributed version control system

Mais conteúdo relacionado

Mais procurados

Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & IntentsLope Emano
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto CompleteOum Saokosal
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Androidma-polimi
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and ActivityNikmesoft Ltd
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxvishal choudhary
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentRaman Pandey
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAnuchit Chalothorn
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 

Mais procurados (20)

Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete07.3. Android Alert message, List, Dropdown, and Auto Complete
07.3. Android Alert message, List, Dropdown, and Auto Complete
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and Activity
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Android UI Fundamentals part 1
Android UI Fundamentals part 1Android UI Fundamentals part 1
Android UI Fundamentals part 1
 
Android app
Android appAndroid app
Android app
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Android intent
Android intentAndroid intent
Android intent
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; Share
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
android activity
android activityandroid activity
android activity
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
Android intents
Android intentsAndroid intents
Android intents
 
Android components
Android componentsAndroid components
Android components
 
Android Lesson 2
Android Lesson 2Android Lesson 2
Android Lesson 2
 

Destaque

07.4. Android Basic Simple Browser (WebView)
07.4. Android Basic Simple Browser (WebView)07.4. Android Basic Simple Browser (WebView)
07.4. Android Basic Simple Browser (WebView)Oum Saokosal
 
10.1. Android Audio
10.1. Android Audio10.1. Android Audio
10.1. Android AudioOum Saokosal
 
04. Review OOP with Java
04. Review OOP with Java04. Review OOP with Java
04. Review OOP with JavaOum Saokosal
 
10.3 Android Video
10.3 Android Video10.3 Android Video
10.3 Android VideoOum Saokosal
 
06. Android Basic Widget and Container
06. Android Basic Widget and Container06. Android Basic Widget and Container
06. Android Basic Widget and ContainerOum Saokosal
 
11.1 Android with HTML
11.1 Android with HTML11.1 Android with HTML
11.1 Android with HTMLOum Saokosal
 
Java Programming - Polymorphism
Java Programming - PolymorphismJava Programming - Polymorphism
Java Programming - PolymorphismOum Saokosal
 
Objected-Oriented Programming with Java
Objected-Oriented Programming with JavaObjected-Oriented Programming with Java
Objected-Oriented Programming with JavaOum Saokosal
 
10.2 Android Audio with SD Card
10.2 Android Audio with SD Card10.2 Android Audio with SD Card
10.2 Android Audio with SD CardOum Saokosal
 
07.1. Android Even Handling
07.1. Android Even Handling07.1. Android Even Handling
07.1. Android Even HandlingOum Saokosal
 
Java Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract ClassJava Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract ClassOum Saokosal
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - InheritanceOum Saokosal
 
12. Android Basic Google Map
12. Android Basic Google Map12. Android Basic Google Map
12. Android Basic Google MapOum Saokosal
 
Database Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS AccessDatabase Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS AccessOum Saokosal
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)Oum Saokosal
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Oum Saokosal
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceOum Saokosal
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFOum Saokosal
 
A Product Manager's Job
A Product Manager's JobA Product Manager's Job
A Product Manager's Jobjoshelman
 

Destaque (20)

07.4. Android Basic Simple Browser (WebView)
07.4. Android Basic Simple Browser (WebView)07.4. Android Basic Simple Browser (WebView)
07.4. Android Basic Simple Browser (WebView)
 
10.1. Android Audio
10.1. Android Audio10.1. Android Audio
10.1. Android Audio
 
04. Review OOP with Java
04. Review OOP with Java04. Review OOP with Java
04. Review OOP with Java
 
10.3 Android Video
10.3 Android Video10.3 Android Video
10.3 Android Video
 
06. Android Basic Widget and Container
06. Android Basic Widget and Container06. Android Basic Widget and Container
06. Android Basic Widget and Container
 
11.1 Android with HTML
11.1 Android with HTML11.1 Android with HTML
11.1 Android with HTML
 
Java Programming - Polymorphism
Java Programming - PolymorphismJava Programming - Polymorphism
Java Programming - Polymorphism
 
Objected-Oriented Programming with Java
Objected-Oriented Programming with JavaObjected-Oriented Programming with Java
Objected-Oriented Programming with Java
 
10.2 Android Audio with SD Card
10.2 Android Audio with SD Card10.2 Android Audio with SD Card
10.2 Android Audio with SD Card
 
07.1. Android Even Handling
07.1. Android Even Handling07.1. Android Even Handling
07.1. Android Even Handling
 
Java Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract ClassJava Programming - Introduction to Abstract Class
Java Programming - Introduction to Abstract Class
 
Java Programming - Inheritance
Java Programming - InheritanceJava Programming - Inheritance
Java Programming - Inheritance
 
12. Android Basic Google Map
12. Android Basic Google Map12. Android Basic Google Map
12. Android Basic Google Map
 
Database Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS AccessDatabase Concept - ERD Mapping to MS Access
Database Concept - ERD Mapping to MS Access
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Natalie Portier, Appodeal
Natalie Portier, Appodeal	Natalie Portier, Appodeal
Natalie Portier, Appodeal
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 
A Product Manager's Job
A Product Manager's JobA Product Manager's Job
A Product Manager's Job
 

Semelhante a Using intents in android

Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database faiz324545
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Hello android world
Hello android worldHello android world
Hello android worldeleksdev
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfAbdullahMunir32
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semaswinbiju1652
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycleKumar
 
How to integrate flurry in android
How to integrate flurry in androidHow to integrate flurry in android
How to integrate flurry in androidadityakumar2080
 
Android application development
Android application developmentAndroid application development
Android application developmentMd. Mujahid Islam
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentalsAmr Salman
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptBirukMarkos
 

Semelhante a Using intents in android (20)

Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
ANDROID
ANDROIDANDROID
ANDROID
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Hello android world
Hello android worldHello android world
Hello android world
 
Intents are Awesome
Intents are AwesomeIntents are Awesome
Intents are Awesome
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Activity & Shared Preference
Activity & Shared PreferenceActivity & Shared Preference
Activity & Shared Preference
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
How to integrate flurry in android
How to integrate flurry in androidHow to integrate flurry in android
How to integrate flurry in android
 
Android application development
Android application developmentAndroid application development
Android application development
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
 
Android Development Basics
Android Development BasicsAndroid Development Basics
Android Development Basics
 
Unit2
Unit2Unit2
Unit2
 
Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
 

Último

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 

Último (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Using intents in android

  • 1. Using Intents in Android This article describes how to use intents in Android. It is based on Eclipse 3.7, Java 1.6 and Android 2.3.3 (Gingerbread). Tabl eof Contents 1. Android Intents 1.1. Overview 1.2. Implicit vrsExplicit Intents 1.3. Getting theIntent datain the called Activity 1.4. Intent Filter 1.5. Intentsas event triggers 1.6. Starting Activitiesand Sub-Activities 1.7. Android Basics 2. Implicit Intents- Opening an URL 3. Explicit intentsand data transfer betweenactivities 4. Registering via Intentfilter 5. Notification Manager 5.1. Notification Manager 5.2. Example 6. Finding out ifan intent isavailable 7. Thankyou 8. Questionsand Discussion 9. Links and Literature 9.1. Source Code 9.2. Android Resources 9.3. vogellaResources 1. Android Intents 1.1. Overview Objects of type "android.content.Intent"are used to send asynchronous messages within your application or between applications. Intents allow to send or receive datafrom and to other activities or services. They also allow to broadcast that a certain event has occurred. Intents are a powerful concept as they allow the creation of loosely coupled applications. Intents can be u sed to communicate between any installed application component on the device. An Intent object can contain information for the receiving component. For example ifyour application calls via an Intent a browser it maysend the URL to the browser component. An Intent also contain information for the Android system so that the Android system can determine which com ponent should handle the request. 1.2. Implicit vrsExplicit Intents Android su pports explicit intents and implicit intents. Explicit intent names the component, e.g. the Java class which should be called. Im plicit intents asked the system to perform a service w ithout tellingthe system whichJava class should do this service. In constructing an im plicit Intent you specify the action which should be performed and optionally an URI whichshould be used for this action. For example you cou ld tell the system that you want to view (action) a webpage (URI). By startingan intent for this data the system would try to find an application which is registered for thisevent, e.g. a browwer. You canadd more datato the Intent by adding "extras"to the Intent. These are key/value pairs. 1.3. Getting the Intent data in the called Activity To get the Intent information in the called Activity u se the method getIntent(). If the Activity was called via an implicit Intent you canreceive the data and url from this Intent via getAction(), getData() and getExtras(). 1.4. Intent Filter
  • 2. The Android system will determine suitable applications for an implicit intentand if several applicationsexists offer the user the choice toopen one. The determination is based on intent filters, e.g. the class "android.content.IntentFilter". Intent filters are typically defined via the "AndroidManifest.xml"file. To react to a certain implicit intent an application component must register itself via an IntentFilter in the "AndroidManifest.xml"to this event. If a com ponent does not define intent filters it can only be called by explicit intents. 1.5. Intentsasevent triggers Intents canalso be used to broadcast messages into the Android system. An Android application can registerBroadcast Receivers to these ev ents and react accordingly. The Android system also u ses Intents to broadcast system events. Yourapplication can also register to these sy stem events, e.g. a new email has arrived, system boot is complete or a phone call is received and react accordingly. 1.6. Starting Activitiesand Sub-Activities To start an activity u se the method startActivity(Intent) if you do not need a returnvalue from the called activity. If y ou need some information from the called activity u se the method startActivityForResult(). Once the called Activity is finished the method onActivityResult() in the calling activity w ill be called. If you use startActivityForResult() then the activity which is started i s considered a "Su b- Activity". 1.7. Android Basics The followingassumes that you have already basic knowledge in Android development . Please check the Android development tutorial to learn the basics. 2. Implicit Intents - Opening an URL The followingcreatesan examle project for calling several implicit intent. The Android system is asked to display a URI and chooses the corresponding application for the right URI. Create a new Android application "de.vogella.android.inten t.implicit"w ith the Activity "CallIntents". Create the following view layout. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Call browser" android:onClick="callIntent"></Button> <Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Call Someone" android:width="100px" android:onClick="callIntent"></Button> <Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Dial" android:width="100px" android:onClick="callIntent"></Button> <Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show Map" android:width="100px" android:onClick="callIntent"></Button>
  • 3. <Button android:id="@+id/Button05" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Search on Map" android:width="100px" android:onClick="callIntent"></Button> <Button android:id="@+id/Button06" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Take picture" android:width="100px" android:onClick="callIntent"></Button> <Button android:id="@+id/Button07" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Show contacts" android:width="100px" android:onClick="callIntent"></Button> <Button android:id="@+id/Button08" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Edit first contact" android:width="100px" android:onClick="callIntent"></Button> </LinearLayout> To be able to use certain intents you need to register then for your application. Maintain the following "AndroidManifest.xml". <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.vogella.android.intent.implicit" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".CallIntents" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="9" /> <uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission> <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.CAMERA"></uses-permission> <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
  • 4. </manifest> Change your activity to the following. We will start the new intent with the method startActivityForResult() which allow us t o specify a desired resu lt code. Once the intent is finished the method onActivityResult() is called and you canperform actions based on the result of the activity. package de.vogella.android.intent.implicit; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class CallIntents extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void callIntent(View view) { Intent intent = null; switch (view.getId()) { case R.id.Button01: intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.vogella.de")); startActivity(intent); break; case R.id.Button02: intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:(+49)12345789"));
  • 5. startActivity(intent); break; case R.id.Button03: intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:(+49)12345789")); startActivity(intent); break; case R.id.Button04: intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:50.123,7.1434?z=19")); startActivity(intent); break; case R.id.Button05: intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=query")); startActivity(intent); break; case R.id.Button06: intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, 0); break; case R.id.Button07: intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/")); startActivity(intent); break; case R.id.Button08: intent = new Intent(Intent.ACTION_EDIT, Uri.parse("content://contacts/people/1")); startActivity(intent); break; default: break; } } @Override
  • 6. public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == 0) { String result = data.toURI(); Toast.makeText(this, result, Toast.LENGTH_LONG); } } } If y ou start yourapplication you should see an list of buttonsand if you press the button, different activities should be p erformed. Note that you do not specify any specific application. 3. Explicit intents and data transfer between activities The followingdemonstrates how you cantransfer databetween two activities. We will use explicit intents in this example and create two activities. The first activity will call the second one via an explicit intent. This second activity will receive data from the first one via the class "Bu ndle"which canbe retrieved via intent.getExtras(). The second activity canbe finished either via the back button on the phone or via the button. The method fin ish() is performed in this case. In this method you cantransfer some data back to the calling activity. This is possible because we u se the method startActivity ForResult(). If you start an activity via this method the method onActivity result is called on the callingactivity once the called activity is finshed. Create a new Android application "de.vogella.android.intent.explicit"w ith the Activity "ActivityOne". Change the layout "main.xml"to the follow ing. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First Activity. Press button to call second activity" android:minHeight="60dip" android:textSize="20sp"></TextView> </LinearLayout> <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content"></LinearLayout> <Button android:id="@+id/Button01" android:layout_width="wrap_content"
  • 7. android:layout_height="wrap_content" android:onClick="onClick" android:text="Calling an intent"></Button> </LinearLayout> Create the layout "second.xml". <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First value from Activity 1"></TextView> <EditText android:text="@+id/EditText01" android:id="@+id/EditText01" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText> </LinearLayout> <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second Value from Activity one"></TextView> <EditText android:text="@+id/EditText02" android:id="@+id/EditText02" android:layout_width="wrap_content" android:layout_height="wrap_content"></EditText> </LinearLayout> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick" android:text="Finished this activity"></Button> </LinearLayout> Create a new activity "ActivityTwo"via the AndroidManifest.
  • 8. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.vogella.android.intent.explicit" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ActivityOne" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:label="ActivityTwo" android:name="ActivityTwo"></activity> </application> <uses-sdk android:minSdkVersion="9" /> </manifest> Create the following coding for your two activities. The second activity will be called from the first one, displays the transferred dataand ifyou select the button of the back button on the phone you send some data back tot the callingapplication. package de.vogella.android.intent.explicit; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class ActivityOne extends Activity { private static final int REQUEST_CODE = 10;
  • 9. /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onClick(View view) { Intent i = new Intent(this, ActivityTwo.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo"); // Set the request code to any code you like, you can identify the // callback via this code startActivityForResult(i, REQUEST_CODE); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) { if (data.hasExtra("returnKey1")) { Toast.makeText(this, data.getExtras().getString("returnKey1"), Toast.LENGTH_SHORT).show(); } } } } package de.vogella.android.intent.explicit; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View;
  • 10. import android.widget.EditText; public class ActivityTwo extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.second); Bundle extras = getIntent().getExtras(); if (extras == null) { return; } String value1 = extras.getString("Value1"); String value2 = extras.getString("Value2"); if (value1 != null && value2 != null) { EditText text1 = (EditText) findViewById(R.id.EditText01); EditText text2 = (EditText) findViewById(R.id.EditText02); text1.setText(value1); text2.setText(value2); } } public void onClick(View view) { finish(); } @Override public void finish() { Intent data = new Intent(); data.putExtra("returnKey1", "Swinging on a star. "); data.putExtra("returnKey2", "You could be better then you are. "); setResult(RESULT_OK, data);
  • 11. super.finish(); } } 4. Registering via Intentfilter You r application canalso register ifself for implicit intentsin Eclipse. For this you have to specify an intent filter for the selected event. Intent filters are typically declared in "AndroidManifest.xml". An intent filter must specify category, action and data filters. Lets create a small browser. Ourapplication will register itself as a browser and will display the HTML code for a giving webpage. Create the Android project "de.vogella.android.intent.browserfilter"w ith the activity "BrowserActivitiy". Change "AndroidManifest.mf"to the follow ing to register your application to the browser view intent. THe following also request the permission to access the Internet. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.vogella.android.intent.browserfilter" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".BrowserActivitiy" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http"/> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="9" /> <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest> Change "main.xml"to the following.
  • 12. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView"/> </LinearLayout> As y our activity gets called withan intent you canget the data from the intent and display it in your application. package de.vogella.android.intent.browserfilter; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.widget.TextView; public class BrowserActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
  • 13. setContentView(R.layout.main); Intent intent = getIntent(); TextView text = (TextView) findViewById(R.id.textView); // To get the action of the intent use System.out.println(intent.getAction()); // We current open a hard-coded URL // To get the data the intent use the following line //Uri data = intent.getData(); URL url; try { // url = new URL(data.getScheme(), data.getHost(), data.getPath()); url = new URL("http://www.vogella.de"); BufferedReader rd = new BufferedReader(new InputStreamReader( url.openStream())); String line = ""; while ((line = rd.readLine()) != null) { text.append(line); } } catch (Exception e) { e.printStackTrace(); } } } If y ou call and URL you should be able to select your browser and the HTML code should be loaded into your textview.
  • 14.
  • 15. 5. Notification Manager 5.1. Notification Manager To pu t a notification into the title barof Android you use the notification manager. The user canopen the notification bar and from the notification another activity canget triggered. You u se the "NotificationManager"class which canbe received from the Activity via getSystemService(). You then configure you class "Notification"and create an intent you will call the target activity. The followingu ses a PendingIntent whichis described in Android Services and PendingIntents . 5.2. Example Create a new project "de.vogella.android.notificationmanager"w ith the Activity "CreateNotification". Create the following layout "result.xml". <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="This is the result activity opened from the notification"
  • 16. android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView1"></TextView> </LinearLayout> Change "main.xml"to the following. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:text="Create Notification" android:onClick="createNotification" android:id="@+id/button1" android:layout_height="match_parent" android:layout_width="match_parent"></Button> </LinearLayout> Create a new activity "NotificationReceiver"w ith the following coding. Don't forget to register the activity in the "Android Manfest.mf". package de.vogella.android.notificationmanager; import android.app.Activity; import android.os.Bundle; public class NotificationReceiver extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.result); } } Change the activity "CreateNotification"to the following.
  • 17. package de.vogella.android.notificationmanager; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.view.View; public class CreateNotification extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void createNotification(View view) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon, "A new notification", System.currentTimeMillis()); // Hide the notification after its selected notification.flags |= Notification.FLAG_AUTO_CANCEL; Intent intent = new Intent(this, NotificationReceiver.class); PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0); notification.setLatestEventInfo(this, "This is the title", "This is the text", activity); notification.number += 1; notificationManager.notify(0, notification);
  • 18. } } Ru n your application and pressthe button. A new notification is created. If y ou select it your second activity will be displayed. 6. Finding out if an intent is available Som etimes you want to find ifan application is available for a certain intent. This canbe done via checking the PackageManager. The following code checks if an intent exists. You can check via this method for intent and change yourapplication behavior accordingly fo r example disable or hide menu items. This tip is based on a blog entry from Romain Guy . public boolean isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
  • 19. PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo.size() > 0) { return true; } return false; } 7. Thank you Please help me to support thisarticle: 8. Questions and Discussion Before posting questions, please see the vogella FAQ . If y ou have qu estions or find an error in this article please use the www.vogella.de Google Group . I have created a short list how to create good questions w hichmight also help you. 9. Links and Literature 9.1. Source Code Source Code of Examples 9.2. Android Resources Android Location API and Google Maps Android and Netw orking Android Homepage Android Issues / Bugs Android Google Groups 9.3. vogella Resources Eclipse RCP Training (German) Eclipse RCP Training with LarsVogel Android Tutorial Introduction to Android Programming
  • 20. GWT Tutorial Program in Java and compile to JavaScript and HTML Eclipse RCP Tutorial Create native applications in Java JUnit Tutorial Test your application Git Tutorial Pu t everything you have under distributed version control system