当前位置: 首页>>代码示例>>Java>>正文


Java Contacts.openContactPhotoInputStream方法代码示例

本文整理汇总了Java中android.provider.ContactsContract.Contacts.openContactPhotoInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Contacts.openContactPhotoInputStream方法的具体用法?Java Contacts.openContactPhotoInputStream怎么用?Java Contacts.openContactPhotoInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.provider.ContactsContract.Contacts的用法示例。


在下文中一共展示了Contacts.openContactPhotoInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getContactPhoto

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
@Override
public Bitmap getContactPhoto(Context ctxt, Uri uri, boolean hiRes, Integer defaultResource) {
    Bitmap img = null;
    InputStream s = Contacts.openContactPhotoInputStream(
            ctxt.getContentResolver(), uri, hiRes);
    img = BitmapFactory.decodeStream(s);

    if (img == null && defaultResource != null) {
        BitmapDrawable drawableBitmap = ((BitmapDrawable) ctxt.getResources().getDrawable(
                defaultResource));
        if (drawableBitmap != null) {
            img = drawableBitmap.getBitmap();
        }
    }
    return img;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:17,代码来源:ContactsUtils14.java

示例2: loadContactPhoto

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
/**
 * Opens an InputStream for the person's photo and returns the photo as a Bitmap. If the
 * person's photo isn't present returns the placeholderImageResource instead.
 *
 * @param context the Context
 *                the id of the person
 * @param options the decoding options, can be set to null
 */
@SuppressLint("NewApi")
public static Bitmap loadContactPhoto(Context context, Uri contactUri,
                                      BitmapFactory.Options options) {

    if (contactUri == null) {
        return null;
    }

    final InputStream stream;
    if (SMSUtils.isICS()) {
        stream = Contacts.openContactPhotoInputStream(context.getContentResolver(),
                contactUri, true);
    } else {
        stream = Contacts.openContactPhotoInputStream(context.getContentResolver(),
                contactUri);
    }

    return stream != null ? BitmapFactory.decodeStream(stream, null, options) : null;
}
 
开发者ID:RSenApps,项目名称:Commandr-Android,代码行数:28,代码来源:SMSUtils.java

示例3: getProfilePicture

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
private static Asset getProfilePicture(ContentResolver contentResolver, Context context,
                                       long contactId) {
    if (contactId != -1) {
        // Try to retrieve the profile picture for the given contact.
        Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
        InputStream inputStream = Contacts.openContactPhotoInputStream(contentResolver,
                contactUri, true /*preferHighres*/);

        if (null != inputStream) {
            try {
                Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                if (bitmap != null) {
                    return Asset.createFromBytes(toByteArray(bitmap));
                } else {
                    Log.e(TAG, "Cannot decode profile picture for contact " + contactId);
                }
            } finally {
                closeQuietly(inputStream);
            }
        }
    }
    // Use a default background image if the user has no profile picture or there was an error.
    return getDefaultProfile(context.getResources());
}
 
开发者ID:mauimauer,项目名称:AndroidWearable-Samples,代码行数:25,代码来源:CalendarQueryService.java

示例4: openPhoto

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public InputStream openPhoto(Context context){
	InputStream input = null;
	Uri uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, this.id);
	//input = Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);
	int sdk = android.os.Build.VERSION.SDK_INT;
   	if(sdk < VERSION_CODES.HONEYCOMB)
   		input = Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);
   	else{
   		try{
   			input = Contacts.openContactPhotoInputStream(context.getContentResolver(), uri, true);
   		}catch(Exception ex){
   			Toast.makeText(context, "Error input hd photo\n"+ex.toString(), Toast.LENGTH_LONG).show();
   		}
   	}
   	return input;
}
 
开发者ID:lheido,项目名称:LheidoSMS-old,代码行数:18,代码来源:LheidoContact.java

示例5: getContactPhoto

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
public Bitmap getContactPhoto(Context ctxt, Uri uri, boolean hiRes, Integer defaultResource) {
    Bitmap img = null;
    InputStream s = Contacts.openContactPhotoInputStream(
            ctxt.getContentResolver(), uri);
    img = BitmapFactory.decodeStream(s);

    if (img == null && defaultResource != null) {
        BitmapDrawable drawableBitmap = ((BitmapDrawable) ctxt.getResources().getDrawable(
                defaultResource));
        if (drawableBitmap != null) {
            img = drawableBitmap.getBitmap();
        }
    }
    return img;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:16,代码来源:ContactsUtils5.java

示例6: findContactImage

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
Uri findContactImage(Context context, String displayNameToFind) {
    Cursor cursor = null;
    try {
        String selection = "UPPER(display_name) = UPPER(?)";
        String[] selectionParams = new String[1];
        String[] columns = new String[]{"_id"};
        selectionParams[0] = displayNameToFind;
        cursor = context.getContentResolver().query(Contacts.CONTENT_URI, columns, "UPPER(display_name) = UPPER(?)", selectionParams, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Uri imageUri = null;
    if (cursor != null && cursor.getCount() > 0) {
        while (cursor.moveToNext()) {
            long id = cursor.getLong(cursor.getColumnIndex("_id"));
            try {
                InputStream inputStream = Contacts.openContactPhotoInputStream(context.getContentResolver(), ContentUris.withAppendedId(Contacts.CONTENT_URI, id));
                if (inputStream != null) {
                    imageUri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(id));
                    break;
                } else if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
    if (cursor != null) {
        cursor.close();
    }
    return imageUri != null ? imageUri : null;
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:34,代码来源:ProfilePhotoManager.java

示例7: getStreamFromContent

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException {
    ContentResolver res = this.context.getContentResolver();
    Uri uri = Uri.parse(imageUri);
    if (isVideoUri(uri)) {
        Bitmap bitmap = Thumbnails.getThumbnail(res, Long.valueOf(uri.getLastPathSegment()).longValue(), 1, null);
        if (bitmap != null) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.PNG, 0, bos);
            return new ByteArrayInputStream(bos.toByteArray());
        }
    } else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) {
        return Contacts.openContactPhotoInputStream(res, uri);
    }
    return res.openInputStream(uri);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:16,代码来源:BaseImageDownloader.java

示例8: getContactPhotoStream

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
@TargetApi(14)
protected InputStream getContactPhotoStream(Uri uri) {
    ContentResolver res = this.context.getContentResolver();
    if (VERSION.SDK_INT >= 14) {
        return Contacts.openContactPhotoInputStream(res, uri, true);
    }
    return Contacts.openContactPhotoInputStream(res, uri);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:9,代码来源:BaseImageDownloader.java

示例9: retrieveContactPhoto

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
private Bitmap retrieveContactPhoto() {

        Bitmap photo = null;
        Cursor cursorID = getContentResolver().query(uriContact, new String[]{Contacts._ID}, null, null, null);

        String contactID = "";
        if (cursorID != null && cursorID.moveToFirst()) {
            contactID = cursorID.getString(cursorID.getColumnIndex(Contacts._ID));
            cursorID.close();
        }

        try {
            InputStream inputStream = Contacts.openContactPhotoInputStream(getContentResolver(),
                    ContentUris.withAppendedId(Contacts.CONTENT_URI, new Long(contactID)));

            if (inputStream != null) {
                photo = BitmapFactory.decodeStream(inputStream);
                inputStream.close();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return photo;

    }
 
开发者ID:HancelParallelZero,项目名称:hancel_android,代码行数:28,代码来源:BaseActivity.java

示例10: loadAvatarData

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
private byte[] loadAvatarData(Contact entry) {
    byte [] data = null;

    if ((!entry.mIsMe && entry.mPersonId == 0) || entry.mAvatar != null) {
        return null;
    }

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("loadAvatarData: name=" + entry.mName + ", number=" + entry.mNumber);
    }

    // If the contact is "me", then use my local profile photo. Otherwise, build a
    // uri to get the avatar of the contact.
    Uri contactUri = entry.mIsMe ?
            Profile.CONTENT_URI :
            ContentUris.withAppendedId(Contacts.CONTENT_URI, entry.mPersonId);

    InputStream avatarDataStream = Contacts.openContactPhotoInputStream(
            mContext.getContentResolver(),
            contactUri, true);
    try {
        if (avatarDataStream != null) {
            data = new byte[avatarDataStream.available()];
            avatarDataStream.read(data, 0, data.length);
        }
    } catch (IOException ex) {
        //
    } finally {
        try {
            if (avatarDataStream != null) {
                avatarDataStream.close();
            }
        } catch (IOException e) {
        }
    }

    return data;
}
 
开发者ID:moezbhatti,项目名称:qksms,代码行数:39,代码来源:Contact.java

示例11: loadContact

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
/**
 * Retrieves the contact information.
 */
public Player loadContact(ContentResolver contentResolver, Uri contactUri) {
    Player contactInfo = new Player();
    long contactId = -1;

    // Load the display name for the specified person
    Cursor cursor = contentResolver.query(contactUri, new String[]{Contacts._ID, Contacts.DISPLAY_NAME}, null, null, null);
    try {
        if (cursor.moveToFirst()) {
            contactId = cursor.getLong(0);
            contactInfo.setDisplayName(cursor.getString(1));
        }
    } finally {
        cursor.close();
    }

    // Load the phone number (if any).
    cursor = contentResolver.query(Phone.CONTENT_URI, new String[]{Phone.NUMBER}, Phone.CONTACT_ID + "=" + contactId, null, Phone.IS_SUPER_PRIMARY + " DESC");
    try {
        if (cursor.moveToFirst()) {
            contactInfo.setPhoneNumber(cursor.getString(0));
        }
    } finally {
        cursor.close();
    }
    
    Uri contactPhotoUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
    InputStream image_stream = Contacts.openContactPhotoInputStream(contentResolver, contactPhotoUri);
 if (image_stream != null) {
 	contactInfo.setPhoto(BitmapFactory.decodeStream(image_stream));
 } 

 contactInfo.setId(contactId);
    contactInfo.setUri(contactUri);
    return contactInfo;
}
 
开发者ID:lebesnec,项目名称:Poker-Director,代码行数:39,代码来源:ContactAccessor.java

示例12: fetchAllPlayers

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
public ArrayList<Player> fetchAllPlayers(long tournamentRowId, ContentResolver contentResolver) {
    Cursor c = mDb.query(DATABASE_TABLE_PLAYERS, new String[] {KEY_PLAYERS_ROWID, KEY_PLAYERS_TOURNAMENTID, KEY_PLAYERS_PLAYERID, KEY_PLAYERS_PLAYERNAME, KEY_PLAYERS_TABLE, KEY_PLAYERS_SEAT}, KEY_PLAYERS_TOURNAMENTID + "=" + tournamentRowId, null, null, null, null);
    
    try {
    	ArrayList<Player> result = new ArrayList<Player>(c.getCount());
    	if (c != null && c.moveToFirst()) {
    		int playerIdColumn = c.getColumnIndex(KEY_PLAYERS_PLAYERID);
    		int playerRowIdColumn = c.getColumnIndex(KEY_PLAYERS_ROWID);
    		int playerNameColumn = c.getColumnIndex(KEY_PLAYERS_PLAYERNAME);
    		int playerTableColumn = c.getColumnIndex(KEY_PLAYERS_TABLE);
    		int playerSeatColumn = c.getColumnIndex(KEY_PLAYERS_SEAT);
     
         do {
	Player player = new Player();
	player.setId(c.getInt(playerIdColumn));
	player.setRowId(c.getInt(playerRowIdColumn));
	if (player.getId() != -1) {
		Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, player.getId());
		player.setUri(contactUri);
        InputStream image_stream = Contacts.openContactPhotoInputStream(contentResolver, contactUri);
	    if (image_stream != null) {
	    	player.setPhoto(BitmapFactory.decodeStream(image_stream));
	    } 
	}
	player.setDisplayName(c.getString(playerNameColumn));
	player.setTable(c.getInt(playerTableColumn));
	player.setSeat(c.getInt(playerSeatColumn));
	
	result.add(player);
			
         } while (c.moveToNext());
    	}
    	
    	return result;
    	
    } finally {
    	c.close();
    }
}
 
开发者ID:lebesnec,项目名称:Poker-Director,代码行数:40,代码来源:DatabaseAccess.java

示例13: newView

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
	float density = context.getResources().getDisplayMetrics().density;
	TextView name = new TextView(context);
	name.setText(cursor.getString(1));
	name.setTag(cursor.getLong(0));
	name.setGravity(Gravity.CENTER_VERTICAL);
	name.setTextColor(Color.BLACK);
	name.setTextSize(19);
	name.setHeight((int) (54 * density));
	
	Uri contactPhotoUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, cursor.getLong(0));
	InputStream image_stream = Contacts.openContactPhotoInputStream(mContent, contactPhotoUri);
	
	Drawable avatar;
 if (image_stream != null) {
 	Bitmap b = BitmapFactory.decodeStream(image_stream);
 	avatar = new BitmapDrawable(b);
 } else {
 	avatar = context.getResources().getDrawable(R.drawable.contact_picture);
 }
 
 avatar.setBounds(0, 0, (int) (54 * density), (int) (54 * density));	    	
	name.setCompoundDrawablePadding((int) (3 * density));
	name.setCompoundDrawables(avatar, null, null, null);
 return name;
}
 
开发者ID:lebesnec,项目名称:Poker-Director,代码行数:28,代码来源:ContactListAdapter.java

示例14: bindView

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
@Override
public void bindView(View view, Context context, Cursor cursor) {
  ImageView image = (ImageView) view.findViewById(R.id.receiver_image);

  if (preferences.getBoolean("show_pictures", true)) {
    InputStream input = Contacts.openContactPhotoInputStream(
        context.getContentResolver(),
        ContentUris.withAppendedId(Contacts.CONTENT_URI, cursor.getInt(1)));
    if (input != null) {
      image.setImageBitmap(BitmapFactory.decodeStream(input));
    } else {
      image.setImageBitmap(BitmapFactory.decodeResource(
          context.getResources(), R.drawable.ic_contact_picture));
    }
  } else {
    image.setVisibility(View.GONE);
  }

  TextView name = (TextView) view.findViewById(R.id.receiver_name);
  name.setText(cursor.getString(2));

  TextView type = (TextView) view.findViewById(R.id.receiver_type);
  type.setText(Phone.getTypeLabel(context.getResources(), cursor.getInt(4),
      cursor.getString(5)));

  TextView number = (TextView) view.findViewById(R.id.receiver_number);
  number.setText(cursor.getString(3));
}
 
开发者ID:adepasquale,项目名称:esms,代码行数:29,代码来源:ReceiverAdapter.java

示例15: loadAvatarData

import android.provider.ContactsContract.Contacts; //导入方法依赖的package包/类
private byte[] loadAvatarData(Contact entry) {
    byte [] data = null;

    if ((!entry.mIsMe && entry.mPersonId == 0) || entry.mAvatar != null) {
        return null;
    }

    if (Log.isLoggable(LogTag.CONTACT, Log.DEBUG)) {
        log("loadAvatarData: name=" + entry.mName + ", number=" + entry.mNumber);
    }

    // If the contact is "me", then use my local profile photo. Otherwise, build a
    // uri to get the avatar of the contact.
    Uri contactUri = entry.mIsMe ?
            Profile.CONTENT_URI :
            ContentUris.withAppendedId(Contacts.CONTENT_URI, entry.mPersonId);

    InputStream avatarDataStream = Contacts.openContactPhotoInputStream(
                mContext.getContentResolver(),
                contactUri);
    try {
        if (avatarDataStream != null) {
            data = new byte[avatarDataStream.available()];
            avatarDataStream.read(data, 0, data.length);
        }
    } catch (IOException ex) {
        //
    } finally {
        try {
            if (avatarDataStream != null) {
                avatarDataStream.close();
            }
        } catch (IOException e) {
        }
    }

    return data;
}
 
开发者ID:CommonQ,项目名称:sms_DualCard,代码行数:39,代码来源:Contact.java


注:本文中的android.provider.ContactsContract.Contacts.openContactPhotoInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。