android.content.Intent.getData()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(299)

本文整理了Java中android.content.Intent.getData()方法的一些代码示例,展示了Intent.getData()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.getData()方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:getData

Intent.getData介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

protected void onActivityResult(int requestCode, int resultCode, 
    Intent imageReturnedIntent) {
  super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

  switch(requestCode) { 
  case REQ_CODE_PICK_IMAGE:
    if(resultCode == RESULT_OK){  
      Uri selectedImage = imageReturnedIntent.getData();
      String[] filePathColumn = {MediaStore.Images.Media.DATA};

      Cursor cursor = getContentResolver().query(
                selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String filePath = cursor.getString(columnIndex);
      cursor.close();

      Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
    }
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

@Override
protected ArrayList<String> workInBackground(RefreshMode mode, String previousPage, String nextPage, Void... params) throws TaskException {
  ArrayList picFileList = new ArrayList<String>();
  Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  Uri uri = intent.getData();
  String[] proj = { MediaStore.Images.Media.DATA };
  Cursor cursor = GlobalContext.getInstance().getContentResolver().query(uri, proj, null, null, null);
  while (cursor.moveToNext()) {
    String path = cursor.getString(0);
    if (TextUtils.isEmpty(path)) {
      continue;
    }
    Logger.d(path);
    picFileList.add(new File(path).getAbsolutePath());
  }
  cursor.close();
  Collections.reverse(picFileList);
  return picFileList;
}

代码示例来源:origin: stackoverflow.com

@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
 super.onActivityResult(reqCode, resultCode, data);

 switch (reqCode) {
  case (PICK_CONTACT) :
   if (resultCode == Activity.RESULT_OK) {
    Uri contactData = data.getData();
    Cursor c =  getContentResolver().query(contactData, null, null, null, null);
    if (c.moveToFirst()) {
     String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
     // TODO Whatever you want to do with the selected contact name.
    }
   }
   break;
 }
}

代码示例来源:origin: stackoverflow.com

@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
     Uri selectedImage = data.getData();
     String[] filePathColumn = { MediaStore.Images.Media.DATA };
     Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
     cursor.moveToFirst();
     int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
     String picturePath = cursor.getString(columnIndex);
     cursor.close();
     ImageView imageView = (ImageView) findViewById(R.id.imgView);
     imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
   }
 }

代码示例来源:origin: stackoverflow.com

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
  super.onActivityResult(requestCode, resultCode, data); 

  switch(requestCode) { 
  case 1234:
    if(resultCode == RESULT_OK){  
      Uri selectedImage = data.getData();
      String[] filePathColumn = {MediaStore.Images.Media.DATA};

      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String filePath = cursor.getString(columnIndex);
      cursor.close();

      Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
      /* Now you have choosen image in Bitmap format in object "yourSelectedImage". You can use it in way you want! */
    }
  }

};

代码示例来源:origin: bumptech/glide

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 if (requestCode == REQUEST_CONTACT && resultCode == RESULT_OK) {
  Uri uri = Preconditions.checkNotNull(data.getData());
  final Cursor cursor = getContentResolver().query(uri, null, null, null, null);
  try {
   if (cursor != null && cursor.moveToFirst()) {
    final long contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID));
    showContact(contactId);
   }
  } finally {
   if (cursor != null) {
    cursor.close();
   }
  }
  return;
 }
 super.onActivityResult(requestCode, resultCode, data);
}

代码示例来源:origin: stackoverflow.com

if (resultCode == RESULT_OK) {
  if (requestCode == SELECT_PICTURE) {
    Uri selectedImageUri = data.getData();
    selectedImagePath = getPath(selectedImageUri);
  if( cursor != null ){
    int column_index = cursor
    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String path = cursor.getString(column_index);
    cursor.close();
    return path;

代码示例来源:origin: north2016/T-MVP

public static String getUrlByIntent(Context mContext, Intent mdata) {
  Uri uri = mdata.getData();
  String scheme = uri.getScheme();
  String data = "";
  if (scheme == null)
    data = uri.getPath();
  else if (ContentResolver.SCHEME_FILE.equals(scheme)) {
    data = uri.getPath();
  } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
    Cursor cursor = mContext.getContentResolver().query(uri,
        new String[]{MediaStore.Images.ImageColumns.DATA},
        null, null, null);
    if (null != cursor) {
      if (cursor.moveToFirst()) {
        int index = cursor.getColumnIndex(
            MediaStore.Images.ImageColumns.DATA);
        if (index > -1) {
          data = cursor.getString(index);
        }
      }
      cursor.close();
    }
  }
  return data;
}

代码示例来源:origin: stackoverflow.com

public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (resultCode == RESULT_OK) {
    switch(requestCode) {
    case SELECT_IMAGE:
      mSelectedImagePath = getPath(data.getData());
      break;
  }
}

public String getPath(Uri uri) {
  String[] projection = { MediaStore.Images.Media.DATA };
  Cursor cursor = managedQuery(uri, projection, null, null, null);
  startManagingCursor(cursor);
  int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  cursor.moveToFirst();
  return cursor.getString(column_index);
}

代码示例来源:origin: stackoverflow.com

public void readcontact(){
  try {
    Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/people"));
    startActivityForResult(intent, PICK_CONTACT);
  } catch (Exception e) {
      e.printStackTrace();
   }
}

public void onActivityResult(int reqCode, int resultCode, Intent data) {
   super.onActivityResult(reqCode, resultCode, data);

   switch (reqCode) {
    case (PICK_CONTACT) :
     if (resultCode == Activity.RESULT_OK) {
       Uri contactData = data.getData();
        Cursor c =  managedQuery(contactData, null, null, null, null);
        startManagingCursor(c);
        if (c.moveToFirst()) {
         String name = c.getString(c.getColumnIndexOrThrow(People.NAME));  
         String number = c.getString(c.getColumnIndexOrThrow(People.NUMBER));
         perrsonname.setText(name);
         Toast.makeText(this,  name + " has number " + number, Toast.LENGTH_LONG).show();
         }
      }
     break;
   }

 }

代码示例来源:origin: stackoverflow.com

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (data != null) {
    Uri uri = data.getData();
            null, null, null);
        if (c != null && c.moveToFirst()) {
          String number = c.getString(0);
          int type = c.getInt(1);
          showSelectedNumber(type, number);
          c.close();

代码示例来源:origin: stackoverflow.com

if (resultCode == Activity.RESULT_OK) {
 Uri contactData = data.getData();
 Cursor c =  managedQuery(contactData, null, null, null, null);
 if (c.moveToFirst()) {
   String id =c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
   String hasPhone =c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
          ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ id, 
          null, null);
     phones.moveToFirst();
     cNumber = phones.getString(phones.getColumnIndex("data1"));
     System.out.println("number is:"+cNumber);
   String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

代码示例来源:origin: stackoverflow.com

if (requestCode == 1)
  if (resultCode == Activity.RESULT_OK) {
    Uri selectedImage = data.getData();
Cursor cursor = managedQuery(uri, projection, null, null, null);
column_index = cursor
    .getColumnIndexOrThrow(MediaColumns.DATA);
cursor.moveToFirst();
imagePath = cursor.getString(column_index);
return cursor.getString(column_index);

代码示例来源:origin: stackoverflow.com

Uri selectedVideoUri = data.getData();
    selectedPath = getPath(selectedVideoUri);
    System.out.println("SELECT_VIDEO Path : " + selectedPath);
String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DURATION}; 
Cursor cursor = managedQuery(uri, projection, null, null, null);
cursor.moveToFirst(); 
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
int fileSize = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
long duration = TimeUnit.MILLISECONDS.toSeconds(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)));

代码示例来源:origin: stackoverflow.com

if (resultCode == RESULT_OK) {
  if (requestCode == SELECT_PICTURE) {
    Uri selectedImageUri = data.getData();
  .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  cursor.moveToFirst();
  return cursor.getString(column_index);

代码示例来源:origin: stackoverflow.com

case RESULT_SELECT_IMAGE:
  if (resultCode == Activity.RESULT_OK && data != null && data.getData() != null) {
    try{
    Uri selectedImage = data.getData();
    String[] filePathColumn = {MediaStore.Images.Media.DATA };
    Cursor cursor = getContentResolver().query(selectedImage,
        filePathColumn, null, null, null);
    cursor.moveToFirst();
    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();

代码示例来源:origin: stackoverflow.com

String email = "", name = "";
try {
  Uri result = data.getData();
  Log.v(DEBUG_TAG, "Got a contact result: " + result.toString());
  int nameId = cursor.getColumnIndex(Contacts.DISPLAY_NAME);
  int emailIdx = cursor.getColumnIndex(Email.DATA);
  if (cursor.moveToFirst()) {
    email = cursor.getString(emailIdx);
    name = cursor.getString(nameId);
    Log.v(DEBUG_TAG, "Got email: " + email);
  } else {
} finally {
  if (cursor != null) {
    cursor.close();

代码示例来源:origin: stackoverflow.com

Uri selectedImage = data.getData();
mTmpGalleryPicturePath = getPath(selectedImage);
if(mTmpGalleryPicturePath!=null)
  .getColumnIndex(MediaStore.Images.Media.DATA);
  cursor.moveToFirst();
  path = cursor.getString(column_index).toString();
  cursor.close();

代码示例来源:origin: stackoverflow.com

int phoneIdx = 0;
try {  
  Uri result = data.getData();  
  String id = result.getLastPathSegment();  
  cursor = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id }, null);  
  phoneIdx = cursor.getColumnIndex(Phone.DATA);
  if (cursor.moveToFirst()) {
    while (cursor.isAfterLast() == false) {
      phoneNumber = cursor.getString(phoneIdx);
      allNumbers.add(phoneNumber);
      cursor.moveToNext();
    cursor.close();

代码示例来源:origin: stackoverflow.com

int phoneIdx = 0;
try {  
  Uri result = data.getData();  
  String id = result.getLastPathSegment();  
  cursor = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id }, null);  
  phoneIdx = cursor.getColumnIndex(Phone.DATA);
  if (cursor.moveToFirst()) {
    while (cursor.isAfterLast() == false) {
      phoneNumber = cursor.getString(phoneIdx);
      allNumbers.add(phoneNumber);
      cursor.moveToNext();
    cursor.close();

相关文章

Intent类方法