简体   繁体   中英

Processing image from a BroadcastReceiver on Android

I´m trying to process an image from a BroadcastReceiver on Android but my log display the following error: call to OpenGL ES API with no current context (logged once per thread). Any ideas. this is my code:

 public void processingImage(String image){

            try {

             if(image != null){

               bmp = convertBitmap(image);
               ByteArrayOutputStream stream = new ByteArrayOutputStream();
               bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
               bitmaps.add(bmp);

               byteArray = stream.toByteArray(); 
             } 


             } catch (Exception e) {

             }
    }

private Bitmap convertBitmap(String image) throws MalformedURLException, IOException{


    Bitmap b = BitmapFactory.decodeStream((InputStream)new URL("http://mydomain.com/upload/" +  image ).getContent());
    return b;
}

You shouldn't do anything in BroadcastReciever other than starting services and activities. BroadcastReceiver instantiated by system with a very limited context which, probably, lacks accelerated graphics support.

android.graphics package contains classes that tightly related to graphic hardware in platform, so Android Context object without actual openGL context can not be used to perform some manipulations specified in this package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM