bjv wrote:

> 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;
>

No need  for this assignment as you throw away the value immediately 
without using it.


>      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");
>

Don't omit the curly braces!
 

>        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);
>

Do not indent your posted code with TAB characters.
 

>      }
>
>     catch (IOException e) {
>
>       MyLog.d(getClass().getSimpleName(), "Exception opening pipe: %s", 
> e.getMessage());
>
>       throw new FileNotFoundException("Could not open pipe for: "
>
>           + uri.toString());
>

You should include the original exception as a cause of your wrapped 
exception, which normally is already 
a 'FileNotFoundException', so one wonders why you'd wrap a FNFE inside an 
FNFE.
 

>      }
>
>
>      return(pipe[0]);
>
> }
>
>
>  class BitmapCopyTask extends AsyncTask<Void,Void,Void> {
>
> OutputStream out;
>

Consider making these members 'final'.
 

>  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);
>

You didn't check the arguments for 'null'.
 

>  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" />
>

-- 
Lew
 

-- 
-- 
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