title: DFactory start: isQmage : stream is not a Qmage file - Contact Badge not loading
body: <p>I've tried several ways to load contact images into a listview and this class works, if there is an image set in the phone. Since that is often not the case I would like to get the facebook profile picture. </p>
  
  <p>I'm using the following class:</p>
  
  <pre><code>public final class QuickContactHelper {
  
  private static final String[] PHOTO_ID_PROJECTION = new String[] {
      ContactsContract.Contacts.PHOTO_ID
  };
  
  private static final String[] PHOTO_BITMAP_PROJECTION = new String[] {
      ContactsContract.CommonDataKinds.Photo.PHOTO
  };
  
  private final QuickContactBadge badge;
  
  private final String phoneNumber;
  
  private final ContentResolver contentResolver;
  
  private final Context myContext;
  
  public QuickContactHelper(final Context context, final QuickContactBadge badge, final String phoneNumber) {
  
      this.badge = badge;
      this.phoneNumber = phoneNumber;
      contentResolver = context.getContentResolver();
      myContext=context;
  
  }
  
  public Bitmap getFacebookPhoto() {
      Uri phoneUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
      Uri photoUri = null;
      Cursor contact = contentResolver.query(phoneUri,
              new String[] { ContactsContract.Contacts._ID }, null, null, null);
  
      if (contact.moveToFirst()) {
          long userId = contact.getLong(contact.getColumnIndex(ContactsContract.Contacts._ID));
          photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, userId);
  
      }
      else {
          Bitmap defaultPhoto = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.ic_contact_picture);
          return defaultPhoto;
      }
      if (photoUri != null) {
          InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(
                  contentResolver, photoUri);
          if (input != null) {
              return BitmapFactory.decodeStream(input);
          }
      } else {
          Bitmap defaultPhoto = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.ic_contact_picture);
          return defaultPhoto;
      }
      Bitmap defaultPhoto = BitmapFactory.decodeResource(myContext.getResources(), R.drawable.ic_contact_picture);
      return defaultPhoto;
  }
  
  public void addThumbnail() {
  
      final Integer thumbnailId = fetchThumbnailId();
      if (thumbnailId != null) {
          final Bitmap thumbnail = fetchThumbnail(thumbnailId);
          if (thumbnail != null) {
              badge.setImageBitmap(thumbnail);
          } 
      }
  
  }
  
  private Integer fetchThumbnailId() {
  
      final Uri uri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
      final Cursor cursor = contentResolver.query(uri, PHOTO_ID_PROJECTION, null, null, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
  
      try {
          Integer thumbnailId = null;
          if (cursor.moveToFirst()) {
              thumbnailId = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_ID));
          }
          return thumbnailId;
      }
      finally {
          cursor.close();
      }
  
  }
  
  final Bitmap fetchThumbnail(final int thumbnailId) {
  
      final Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, thumbnailId);
      final Cursor cursor = contentResolver.query(uri, PHOTO_BITMAP_PROJECTION, null, null, null);
  
      try {
          Bitmap thumbnail = null;
          if (cursor.moveToFirst()) {
              final byte[] thumbnailBytes = cursor.getBlob(0);
              if (thumbnailBytes != null) {
                  thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length);
              }
         }
  
          if (thumbnail == null){
              thumbnail=getFacebookPhoto(); //error: isQmage : stream is not a Qmage file 
          }
  
          return thumbnail;
      }
      finally {
          cursor.close();
      }
  
  }
  
  }
  </code></pre>
  
  <p>When trying to retrieve the bitmap with the method getFacebookPhoto(), it gives me the following error and not the profile picture:</p>
  
  <pre><code>11-20 11:16:26.591: D/(2383): DFactory start
  11-20 11:16:26.591: D/(2383): isQmage : stream is not a Qmage file
  </code></pre>
  
  <p>How do I convert the bitmap into a Qmage file? And does this work for non samsung devices?</p>