0

i want to open vcf file stored in my sdcard in specific folder i want to show the name and phone number in textview or listview if can. this is my code and i know it's not working

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(); 

if i can show the name and phone number in text view.. how i can show it in listview.. please help i need it

user5050715
  • 45
  • 10
  • `want to open vcf file stored in my sdcard in specific folder `. There is nothing in your code that has anything to do with a removable SD card. Further: if you have a file in a folder then it does not make sense to call mkdirs on that folder. Further you are talking too much about a listview if your problem is opening a file. Please rewrite your post. Its a mess now. – greenapps Mar 26 '18 at 09:49
  • can u edit my code please? – user5050715 Mar 26 '18 at 09:50

0 Answers0