从我的应用程序内的sdcard打开vcf文件

时间:2018-03-26 09:39:34

标签: java android vcf

我想在特定文件夹中打开存储在我的SD卡中的vcf文件 我想在textview或listview中显示姓名和电话号码。 这是我的代码,我知道它不起作用

String path1 = Environment.getExternalStorageDirectory()
            .getPath() + "/Mark/Contact/";
        File dir = new File(path1);
        if(!dir.exists())
            dir.mkdirs();

    File    vfile = new File(dir, "a.vcf");
        vfile.canWrite(); 

        Uri uri=Uri.fromFile(new File(path1,""+vfile));

        Cursor c =  getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
        if (c.moveToFirst()) {

            String phoneNumber="",emailAddress="";
            String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
            //http://stackoverflow.com/questions/866769/how-to-call-android-contacts-list   our upvoted answer

            String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

            if ( hasPhone.equalsIgnoreCase("1"))
                hasPhone = "true";
            else
                hasPhone = "false" ;

            if (Boolean.parseBoolean(hasPhone))
            {
                Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
                while (phones.moveToNext())
                {
                    phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                }
                phones.close();
            }

            // Find Email Addresses
            Cursor emails = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,null, null);
            while (emails.moveToNext())
            {
                emailAddress = emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
            }
            emails.close();

            //mainActivity.onBackPressed();
            // Toast.makeText(mainactivity, "go go go", Toast.LENGTH_SHORT).show();
TextView tv1 = (TextView) findViewById(R.id.tv1);
TextView tv2= (TextView) findViewById(R.id.tv2);


            tv1.setText("Name: "+name);
            tv2.setText("Phone: "+phoneNumber);
                        }
        c.close(); 

如果我可以在文本视图中显示姓名和电话号码..我如何在列表视图中显示它...请帮助我需要它

0 个答案:

没有答案