Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While trying to share avatar onRequestPermissionsResult leads to NPE #4

Open
MrCsabaToth opened this issue Sep 5, 2020 · 3 comments
Assignees
Labels

Comments

@MrCsabaToth
Copy link
Member

MrCsabaToth commented Sep 5, 2020

Seeing this in App Store crash reports. Call stack:

java.lang.RuntimeException: 
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4589)
  at android.app.ActivityThread.handleSendResult (ActivityThread.java:4631)
  at android.app.servertransaction.ActivityResultItem.execute (ActivityResultItem.java:49)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:108)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:68)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1893)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loop (Looper.java:192)
  at android.app.ActivityThread.main (ActivityThread.java:7169)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:504)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: 
  at android.net.Uri$StringUri.<init> (Uri.java:490)
  at android.net.Uri$StringUri.<init> (Uri.java:480)
  at android.net.Uri.parse (Uri.java:452)
  at com.valleydevfest.androidify.PlaceholderFragment.share (PlaceholderFragment.java:172)
  at com.valleydevfest.androidify.PlaceholderFragment.onRequestPermissionsResult (PlaceholderFragment.java:156)
  at androidx.fragment.app.FragmentActivity.onRequestPermissionsResult (FragmentActivity.java:768)
  at android.app.Activity.dispatchRequestPermissionsResult (Activity.java:9095)
  at android.app.Activity.dispatchActivityResult (Activity.java:8945)
  at android.app.ActivityThread.deliverResults (ActivityThread.java:4582)

https://play.google.com/console/u/0/developers/7696534728259995393/app/4972777259653312467/vitals/crashes/ce0e7156/details?installedFrom=PLAY_STORE&days=30

Screenshot_2020-09-04_22-27-58

besides those there is also:

  • Samsung Galaxy Grand Prime Plus, Android 6.0 (SDK 23), 23 days ago
  • ZTE Blade A3 Lite, Android 9 (SDK 28), 8 days ago
  • Huawei Y3III, Android 6.0 (SDK 23), 18 days ago
@MrCsabaToth MrCsabaToth added the bug label Sep 5, 2020
@MrCsabaToth MrCsabaToth self-assigned this Sep 5, 2020
@MrCsabaToth MrCsabaToth changed the title onRequestPermissionsResult leads to NPE onRequestPermissionsResult can lead to NPE Sep 5, 2020
@MrCsabaToth
Copy link
Member Author

Here is the share, line 172 is the Uri imageURI = Uri.parse(imagePath);:

    Bitmap bitmap = BitmapUtils.combineDrawables(getResources(), head, body, legs);

    String imagePath = MediaStore.Images.Media.insertImage(
        requireActivity().getContentResolver(), bitmap,
        getResources().getString(R.string.android_avatar), null
    );
    Uri imageURI = Uri.parse(imagePath);
    startShareActivity(imageURI);

This might be a permission issue? Maybe it's the new ScopedStorage related permission changes? https://developer.android.com/about/versions/10/privacy/changes#scoped-storage https://developer.android.com/training/data-storage#scoped-storage ? I wonder if as a workaround reverting target SDK level to API 28 would help. I assume that with the new permissions I cannot simply get a URI of the file.

@MrCsabaToth MrCsabaToth changed the title onRequestPermissionsResult can lead to NPE While trying to share avatar onRequestPermissionsResult leads to NPE Sep 5, 2020
@MrCsabaToth
Copy link
Member Author

https://stackoverflow.com/questions/53913401/mediastore-images-media-insertimage-is-returning-null-when-trying-to-get-image-u

Maybe I should look into FileProvider. Also check if the file permissions are handled well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant