Main. xml is as follows:
[Html]
LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical"
Android: gravity = "center_horizontal"
>
<Button
Android: id = "@ + id/callTelephoneButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/callTelephone"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
<Button
Android: id = "@ + id/browsephotosButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/browsephotos"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
<Button
Android: id = "@ + id/openBrowserButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/openBrowser"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
<Button
Android: id = "@ + id/openCameraButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/openCamera"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
</LinearLayout>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical"
Android: gravity = "center_horizontal"
>
<Button
Android: id = "@ + id/callTelephoneButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/callTelephone"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
<Button
Android: id = "@ + id/browsephotosButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/browsephotos"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
<Button
Android: id = "@ + id/openBrowserButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/openBrowser"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
<Button
Android: id = "@ + id/openCameraButton"
Android: layout_width = "150dip"
Android: layout_height = "40dip"
Android: gravity = "center"
Android: text = "@ string/openCamera"
Android: layout_marginTop = "50dip"
Android: textSize = "20sp"
/>
</LinearLayout> MainActivity is as follows:
[Java]
Package cn.com. bravesoft. testintent;
Import android.net. Uri;
Import android. OS. Bundle;
Import android. provider. MediaStore;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. app. Activity;
Import android. content. Intent;
/**
*
* Official materials:
* 1 permission settings
* Http://developer.android.com/reference/android/Manifest.permission.html
* 2 system Intent
* Http://developer.android.com/reference/android/content/Intent.html#ACTION_CALL
*/
Public class MainActivity extends Activity {
Private Button mTelephoneButton;
Private Button mPhotosButton;
Private Button mBrowserButton;
Private Button mCameraButton;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Init ();
}
Private void init (){
MTelephoneButton = (Button) findViewById (R. id. callTelephoneButton );
MTelephoneButton. setOnClickListener (new ButtonOnClickListenerImpl ());
MPhotosButton = (Button) findViewById (R. id. browsephotosButton );
MPhotosButton. setOnClickListener (new ButtonOnClickListenerImpl ());
MBrowserButton = (Button) findViewById (R. id. openBrowserButton );
MBrowserButton. setOnClickListener (new ButtonOnClickListenerImpl ());
MCameraButton = (Button) findViewById (R. id. openCameraButton );
MCameraButton. setOnClickListener (new ButtonOnClickListenerImpl ());
}
Private class ButtonOnClickListenerImpl implements OnClickListener {
@ Override
Public void onClick (View v ){
Switch (v. getId ()){
Case R. id. callTelephoneButton:
// Call
Intent telephoneIntent = new Intent ();
TelephoneIntent. setAction ("android. intent. action. CALL ");
TelephoneIntent. setData (Uri. parse ("tel:" + "150028068 "));
StartActivity (telephoneIntent );
Break;
Case R. id. browsephotosButton:
// View the image
Intent galleryIntent = new Intent ();
GalleryIntent. setAction (Intent. ACTION_GET_CONTENT );
GalleryIntent. setType ("image /*");
StartActivity (galleryIntent );
Break;
Case R. id. openBrowserButton:
// Open the browser
Intent browserIntent = new Intent ();
BrowserIntent. setAction (Intent. ACTION_VIEW );
BrowserIntent. setData (Uri. parse ("http://www.ifeng.com "));
StartActivity (browserIntent );
Break;
Case R. id. openCameraButton:
// Open the camera
Intent cameraIntent = new Intent (MediaStore. ACTION_IMAGE_CAPTURE );
StartActivity (cameraIntent );
Break;
Default:
Break;
}
}
}
}