Using Crop intent Getting java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy@4266ae80

后端 未结 3 778
南方客
南方客 2020-12-30 06:09

I am using crop intent to crop the image,most of time it run fine,but sometime getting java.lang.SecurityException: Unable to find app for caller android.app.Application

相关标签:
3条回答
  • 2020-12-30 06:24

    This log means that your app is having trouble handling a communication intent. Sometimes problems like this can occur when you send intent with very big extras.

    Passing High resolution photos or big file via extras is not recommended, the best practice is to save the file on the external storage (if you haven't done it yet), get a Uri reference to it and send this ref as String in your intent's extra

    yourIntent.putExtra("MyUriKey", yourUri.toString)

    If you are dealing with an image and quality is not of your concern, you can use a workaround and simply reduce the file's dimension by compressing it.

    0 讨论(0)
  • 2020-12-30 06:31

    I agree with the Roberto Lombardini's answer. Maybe you can try this solution for simple reference.

    1. Save your bitmap into local first with unique name or you own resource id, you can use UUID

      public void savePhotoCache(final String resourceId, final Bitmap bitmap) {
          if(bitmap==null)
              return;
      
          File imageDir = new File(context.getCacheDir(), "images/yourpackagename");
          if (!imageDir.isDirectory())
              imageDir.mkdirs();
      
          File cachedImage = new File(imageDir, resourceId);
          FileOutputStream output = null;
          try {
              output = new FileOutputStream(cachedImage);
              bitmap.compress(PNG, 100, output);
          } catch (IOException e) {
              Log.d("CACHED_IMAGE", "Exception writing cache image", e);
          } finally {
              if (output != null)
                  try {
                      output.close();
                  } catch (IOException e) {
                      // Ignored
                  }
          }
      }
      
    2. When passing to another activity you only pass resource id and get bitmap data in another activity using this function.

      private Bitmap getPhotoCache(final String resourceId) {
          File imageDir = new File(context.getCacheDir(), "images/yourpackagename");
          if (!imageDir.isDirectory())
              imageDir.mkdirs();
      
          File imageFile = new File(imageDir, resourceId);
      
          if (!imageFile.exists() || imageFile.length() == 0)
              return null;
      
          Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
          if (bitmap != null)
              return bitmap;
          else {
              imageFile.delete();
              return null;
          }
      }
      

    I hope this can help you. :)

    0 讨论(0)
  • 2020-12-30 06:37

    In my case, i was passing a byteArray of a bitmap in a intent. After seeing Roberto Lombardini's answer, I changed my code so that it could send the uri of the bitmap instead, and my problem was gone.

    0 讨论(0)
提交回复
热议问题