コード例 #1
0
  /**
   * Saves the contact photo - if present - to a file in private storage and makes sure the object
   * can provide a URI for it.
   */
  public void preparePhotoUri(Context context) {
    if (photo == null) return;

    Bitmap bitmapOriginal = BitmapFactory.decodeByteArray(photo, 0, photo.length);
    if (bitmapOriginal == null) return;

    photoUri = AddressBookProvider.storeBitmap(context, bitmapOriginal);
  }
コード例 #2
0
  public static FindNearbyContact lookupUserRecord(
      ContentResolver contentResolver, Configuration configuration, String bitcoinAddress) {
    FindNearbyContact record = null;
    String name = configuration.getFindNearbyUserName();
    Uri photoUri = configuration.getFindNearbyUserPhoto();

    byte[] photo = null;
    if (photoUri != null) {
      try {
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(contentResolver, photoUri);
        Bitmap scaledBitmap = AddressBookProvider.ensureReasonableSize(bitmap);
        if (scaledBitmap == null) throw new IOException();

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        scaledBitmap.compress(CompressFormat.PNG, 100, outStream);
        photo = outStream.toByteArray();
      } catch (FileNotFoundException ignored) {
      } catch (IOException ignored) {
      }
    }

    record = new FindNearbyContact(bitcoinAddress, name, photo);
    return record;
  }