Ok, it was a bad subject. I just needed a way to provide a Bitmap drawable 
in my App's memory (not on sdcard) to the SearchWidget suggestion handling 
code. Here's the answer for anyone who needs to provide their own image 
that isn't stored somewhere as a file and easily accessible via one of the 
other content providers that are already there.

I created a ContentProvider in my app. The key methods look like the 
following:

@Override

public ParcelFileDescriptor openFile(Uri uri, String mode)

throws FileNotFoundException {

    ParcelFileDescriptor[] pipe=null;


     try {

      pipe=ParcelFileDescriptor.createPipe();

      String bmapId = uri.getLastPathSegment();

      IconInfo ai = getIconInfo.lookup(Integer.parseInt(bmapId));

      if (ai == null)

      throw new FileNotFoundException("Bitmap "+bmapId+" not found");

      Bitmap bitmap = ((BitmapDrawable)ai.icon).getBitmap();

      if (bitmap == null)

      throw new FileNotFoundException("Drawable is not Bitmap");

      // The following task/thread is needed if the bmap is larger than 64kb

      new BitmapCopyTask(bitmap,

                       new AutoCloseOutputStream(pipe[1])).execute(null,null
,null);

    }

    catch (IOException e) {

      MyLog.d(getClass().getSimpleName(), "Exception opening pipe: %s", 
e.getMessage());

      throw new FileNotFoundException("Could not open pipe for: "

          + uri.toString());

    }


     return(pipe[0]);

}


 class BitmapCopyTask extends AsyncTask<Void,Void,Void> {

OutputStream out;

Bitmap bmap;

BitmapCopyThread(Bitmap bmap, OutputStream out) {

this.bmap = bmap;

this.out = out;

}

 @Override

protected Void doInBackground(Void... arg0) {

bmap.compress(Bitmap.CompressFormat.PNG, 100, out);

return null;

}

}

I also put the following provider definition in my manifest file:

        <provider android:name=".IconProvider"

            android:exported="false"

android:authorities="org.example.provider.iconlist.icon" />

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to