Android system call

Source: Internet
Author: User

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;
}
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.