Insert a new contact intent

后端 未结 9 1001
陌清茗
陌清茗 2020-11-30 23:02

For one of my apps, I need the user to select one of his existing contacts or to create a new one. Picking one is clearly easy to do with the following code:



        
9条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 23:57

     int INSERT_CONTACT_REQUEST=2;
     i = new Intent(Intent.ACTION_INSERT,Contacts.CONTENT_URI);
     startActivityForResult(i, INSERT_CONTACT_REQUEST);
    

    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
    // TODO Auto-generated method stub
     if(requestCode == INSERT_CONTACT_REQUEST)
       {
            if (resultCode == RESULT_OK)
                {                                  
                 Toast.makeText().show(getApplicationContext(),"Added_Succesfully",Toast.LENGTH_SHORT);
                }else if(resultCode == RESULT_CANCELED)
                       {
                     Toast.makeText().show(getApplicationContext(),"Contacts Adding Error",Toast.LENGTH_SHORT);     
                        }
    
        }
    }
    

提交回复
热议问题