zoukankan      html  css  js  c++  java
  • Getting a Result from an Activity(by Contact example)

    static final int PICK_CONTACT_REQUEST = 1;  // The request code
    
    private void pickContact() {
        	Uri contacts = Uri.parse("content://contacts");
    	    Intent pickContactIntent = new Intent(Intent.ACTION_PICK, contacts);
    	    pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
    	    startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
    	}
    
    	@Override
    	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    		// Check which request it is that we're responding to
    	    if (requestCode == PICK_CONTACT_REQUEST) {
    	        // Make sure the request was successful
    	        if (resultCode == RESULT_OK) {
    	            // Get the URI that points to the selected contact
    	            Uri contactUri = data.getData();
    	            // We only need the NUMBER column, because there will be only one row in the result
    	            String[] projection = {Phone.NUMBER,Phone.CONTACT_ID};
    
    	            // Perform the query on the contact to get the NUMBER column
    	            // We don't need a selection or sort order (there's only one result for the given URI)
    	            // CAUTION: The query() method should be called from a separate thread to avoid blocking
    	            // your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
    	            // Consider using CursorLoader to perform the query.
    	            Cursor cursor = getContentResolver()
    	                    .query(contactUri, projection, null, null, null);
    	            cursor.moveToFirst();
    
    	            // Retrieve the phone number from the NUMBER column
    	            int column = cursor.getColumnIndex(Phone.NUMBER);
    	            int column_id=cursor.getColumnIndex(Phone.CONTACT_ID);
    	            String number = cursor.getString(column);
    	            String id=cursor.getString(column_id);
    	            EditText edittext=(EditText)findViewById(R.id.edit_message);
    	            edittext.setText(number +id);
    	        }
    	    }
    	}
    

      

  • 相关阅读:
    javascript动态创建Option选项
    Javascript中最常用的25个经典技巧
    C#常用函数和方法集
    C#邮件发送程序
    CSS菜单
    笔记本将有线变无线网
    svn有权限但是不能提交的原因
    IE6在https下认为iframe和about:blank不安全
    VS2008创建MFC项目提示无法找到userimages.bmp
    往数据库中插入流数据的问题
  • 原文地址:https://www.cnblogs.com/nikyxxx/p/2684032.html
Copyright © 2011-2022 走看看