首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阅读SIM卡通讯录

阅读SIM卡通讯录
EN

Stack Overflow用户
提问于 2014-10-31 21:15:32
回答 1查看 305关注 0票数 0

我正在开发一个android应用程序,我想通过一个按钮点击读取或获得SIM卡联系人。你能帮我吗?

我的按钮xml代码是:

代码语言:javascript
复制
<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)。

EN

回答 1

Stack Overflow用户

发布于 2014-11-12 21:57:31

代码语言:javascript
复制
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();
        }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26675599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档