我正在开发一个android应用程序,我想通过一个按钮点击读取或获得SIM卡联系人。你能帮我吗?
我的按钮xml代码是:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/third"
android:layout_below="@+id/third"
android:layout_marginTop="30dp"
android:text="Read contact"
android:onClick="contactsAccess"/>我需要java代码在方法中使用(contactsAccess)。
发布于 2014-11-12 21:57:31
public class MainActivity extends ActionBarActivity implements OnClickListener {
Button sim_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.YOUR_VIEW);
sim_btn = (Button)findViewById(R.id.button1);
sim_btn.setOnClickListener(this);
getallsimnumber();
}
getallsimnumber(){
try
{
String ClsSimPhonename = null;
String ClsSimphoneNo = null;
Uri simUri = Uri.parse("content://icc/adn");
Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null);
Log.i("PhoneContact", "total: "+cursorSim.getCount());
while (cursorSim.moveToNext())
{
ClsSimPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
ClsSimphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
ClsSimphoneNo.replaceAll("\\D","");
ClsSimphoneNo.replaceAll("&", "");
ClsSimPhonename=ClsSimPhonename.replace("|","");
Log.i("PhoneContact", "name: "+ClsSimPhonename+" phone: "+ClsSimphoneNo);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}https://stackoverflow.com/questions/26675599
复制相似问题