Android programming to read mobile phone contact person, dial-up, send SMS and long by menu operation Method Example Summary _android

Source: Internet
Author: User

This article describes the Android programming to read mobile phone contacts, dial-up, send SMS and long by menu operation method. Share to everyone for your reference, specific as follows:

1.Andrid Project Chart ↓ main operation diagram in red box in the file.

2. First layout code is as follows

A, main.xml program to run the main interface, mainly using ListView List control display mobile contact

<?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 "
android: background= "@drawable/bg"
android:orientation= "vertical" >
<listview android:id=
"@+id/ ListView "
android:layout_width=" fill_parent "
android:layout_height=" fill_parent "
android:layout_" marginleft= "5dip" "
android:cachecolorhint=" #00000000 "
android:divider=" @drawable/divider_horizontal_ Bright "
android:paddingright=" 5dip ">
</ListView>
</LinearLayout>

B.list_item.xml ListView The list item layout file, which is equivalent to the demo template

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Fill_parent "android:layout_height=" wrap_content "android:orientation=" Horizontal " > <imageview android:id= "@+id/imgview" android:layout_width= wrap_content "android:layout_height=" Wrap_ Content "android:contentdescription=" @string/photo "android:paddingright=" 2dip "/> <textview android:id=" @+id /name "android:layout_width=" 80dip "android:layout_height=" wrap_content "android:layout_marginleft=" 10dip "Android :p addingtop= "8dip" android:singleline= "false" android:textappearance= "? Android:attr/textappearancemedium" Android : textcolor= "#ffffff"/> <textview android:id= "@+id/number" android:layout_width= "Fill_parent" Android:layout_
height= "Wrap_content" android:layout_marginright= "6dip" android:paddingtop= "8dip" android:singleline= "false" Android:textcolor= "#ffffff" android:textappearance= "Android:attr/textappearancemedium"/> </Linearlayout>

 

C,phonedetails.xml Display contact Detail layout interface by menu, example only does jump show

<?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 "
android:o" rientation= "vertical" >
<textview
android:id= "@+id/ymw" android:layout_width= "Fill_parent"
android:layout_height= "wrap_content"
android:textappearance= "Android:attr/textappearancemedium"/>
</LinearLayout>

2.Java implementation code as follows

The entry file for the A,mainactivity.java program to run

Package com.example.myandroid;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import Java.util.Iterator;
Import android.app.Activity;
Import Android.content.ContentResolver;
Import android.content.Intent;
Import Android.database.Cursor;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.provider.ContactsContract;
Import Android.provider.ContactsContract.CommonDataKinds;
Import Android.view.ContextMenu;
Import Android.view.ContextMenu.ContextMenuInfo;
Import Android.view.MenuItem;
Import Android.view.View;
Import Android.view.View.OnCreateContextMenuListener;
Import Android.widget.AdapterView;
Import Android.widget.AdapterView.OnItemClickListener;
Import Android.widget.ListView;
Import Android.widget.SimpleAdapter;
Import Android.widget.Toast;
Import Com.ymw.details.Detail; public class Mainactivity extends activity {@Override public void onCreate (Bundle savedinstancestate) {super.oncreate (SA
Vedinstancestate);
Setcontentview (R.layout.main); Final ListView ListvieW = (ListView) Findviewbyid (R.id.listview);
Generate dynamic array, add data arraylist 

B,detail.java main interface long by menu display contact details of the jump interface, accept the main interface from the parameters

Package com.ymw.details;
Import COM.EXAMPLE.MYANDROID.R;
Import android.app.Activity;
Import android.content.Intent;
Import Android.os.Bundle;
Import Android.widget.TextView;
public class Detail extends activity {
@Override
protected void onCreate (Bundle savedinstancestate) {
// TODO auto-generated Method Stub
super.oncreate (Savedinstancestate);
Setcontentview (com.example.myandroid.r.layout.phonedetails);
Intent Intent = Getintent ();
String Strpara = Intent.getstringextra ("YMW");
TextView Tview = (TextView) Findviewbyid (R.ID.YMW);
Tview.settext (Strpara);
}


3. Access to mobile phone contacts and dial-up texting, etc. need to configure permissions

Add the following code to the application node in the Androidmanifest.xml file

<!--add permissions-->
<uses-permission android:name= "Android.permission.SEND_SMS"/>
< Uses-permission android:name= "Android.permission.CALL_PHONE"/>
<uses-permission android:name= " Android.permission.READ_CONTACTS "/>

4. Use the Android Simulator or connect to the Android smartphone to run this program to see the Mobile contact list,

Click a contact to dial directly, long press a contact will appear menu options, you can choose to send text messages.

I hope this article will help you with the Android program.

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.