public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mMimeType); mPendingResult = this; startActivityForResult(intent, 1); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pick_contact); // Watch for button clicks. ((Button)findViewById(R.id.pick_contact)).setOnClickListener( new ResultDisplayer("Selected contact", ContactsContract.Contacts.CONTENT_ITEM_TYPE)); ((Button)findViewById(R.id.pick_person)).setOnClickListener( new ResultDisplayer("Selected person", "vnd.android.cursor.item/person")); ((Button)findViewById(R.id.pick_phone)).setOnClickListener( new ResultDisplayer("Selected phone", ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)); ((Button)findViewById(R.id.pick_address)).setOnClickListener( new ResultDisplayer("Selected address", ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { Uri uri = data.getData(); if (uri != null) { Cursor c = null; try { c = getContentResolver().query(uri, new String[] { BaseColumns._ID }, null, null, null); if (c != null && c.moveToFirst()) { int id = c.getInt(0); if (mToast != null) { mToast.cancel(); } String txt = mPendingResult.mMsg + ":\n" + uri + "\nid: " + id; mToast = Toast.makeText(this, txt, Toast.LENGTH_LONG); mToast.show(); } } finally { if (c != null) { c.close(); } } } } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pick_contact); // Watch for button clicks. ((Button)findViewById(R.id.pick_contact)).setOnClickListener( new ResultDisplayer("Selected contact", ContactsContract.Contacts.CONTENT_ITEM_TYPE)); ((Button)findViewById(R.id.pick_person)).setOnClickListener( new ResultDisplayer("Selected person", "vnd.android.cursor.item/person")); ((Button)findViewById(R.id.pick_phone)).setOnClickListener( new ResultDisplayer("Selected phone", ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)); ((Button)findViewById(R.id.pick_address)).setOnClickListener( new ResultDisplayer("Selected address", ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { Uri uri = data.getData(); if (uri != null) { Cursor c = null; try { c = getContentResolver().query(uri, new String[] { BaseColumns._ID }, null, null, null); if (c != null && c.moveToFirst()) { int id = c.getInt(0); if (mToast != null) { mToast.cancel(); } String txt = mPendingResult.mMsg + ":\n" + uri + "\nid: " + id; mToast = Toast.makeText(this, txt, Toast.LENGTH_LONG); mToast.show(); } } finally { if (c != null) { c.close(); } } } } } }
public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mMimeType); mPendingResult = this; startActivityForResult(intent, 1); } }