简体   繁体   English

我无法使用内容提供商在android应用程序中更新我的电子邮件

[英]I am not able to update my email in android application using content provider

i am working on the application which retrieve all the android contacts and also can delete and update contacts.everything working fine problem is when contact does not have email address then i can not update it using my application (can not add email address from my update contact page). 我正在处理可检索所有android联系人的应用程序,并且还可以删除和更新contacts.everything一切正常的问题是当联系人没有电子邮件地址时,我无法使用我的应用程序进行更新(无法从更新中添加电子邮件地址联系页面)。 i have written used code below. 我在下面写了二手代码。 thanks in advance. 提前致谢。

private void updateEmaill(String id, String email) {

    ContentResolver cr = getContentResolver();

    String where = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND "
            + ContactsContract.Data.MIMETYPE + " = ?";

    String[] params = new String[] { id,
            ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE };

    Cursor phoneCur = managedQuery(ContactsContract.Data.CONTENT_URI, null,
            where, params, null);

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    if ((null == phoneCur)) {


        System.out.println("we have got null value from the cursor");

    } else {



        System.out.println("phone cursor count" + phoneCur.getCount());





        ops.add(ContentProviderOperation
                .newUpdate(ContactsContract.Data.CONTENT_URI)
                .withSelection(where, params)
                .withValue(ContactsContract.CommonDataKinds.Email.ADDRESS,
                        email).build());


    }

    phoneCur.close();

    try {

        cr.applyBatch(ContactsContract.AUTHORITY, ops);

    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OperationApplicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

newUpdate() has been known to work only if a given field exists already. 仅当给定字段已经存在时,才知道newUpdate()可以工作。

As a workaround, here's one simple logic you can use: 解决方法是,可以使用以下一种简单逻辑:

  -check if email exists for contacts
  -if it does call update
  -if it doesn't save all the fields of this contact in some variables and delete the  contact
  -use newInsert() to create a new contact with the saved fields from old contact and also the email that you need to add.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以使用Android中的内容提供商访问电子邮件 - is it possible to access email using content provider in android 我无法使用此编码从SD卡中提取歌曲。我可以这样做吗,还是需要内容提供商提供? - I am not able to fetch songs from my SD card using this coding.Can I do this way or I need to do it by Content Provider 无法在android中授予我的自定义内容提供商权限? - Not able to grant my custom content provider permission in android? 我无法完成/关闭我的申请 - I am not able to finish/close my application 我无法在Android应用程序中使用RestApi - I am not able to use RestApi in android application 我正在使用Kinvey作为我的Android应用程序的后端 - I am using Kinvey as my backend for my Android Application 我是否能够在第一次运行应用程序时使用android服务器 - am I able to use android serives in the first time I run my application 我正在使用Android中的内容提供程序创建数据库,但该数据库根本无法正常工作 - I am creating a database with content provider in android,but the database not working at all 由于android studio和adb.exe的更新,我无法运行我的程序 - I am not able to run my program due to update of android studio and adb.exe Android应用程序设置为仅可在平板电脑上部署,但是为什么我仍然可以在手机上安装它? - Android application is set to be deployed on tablets only, but why am I still able to install it on my phone?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM