i been been searching this kind of problem in stack and i could not found it. so i need help from all thank you.
I been using library com.blikoon.qrcodescanner to scan QR CODE. Everything fine before im try to migrating the library and my apps to androidx. after the migration the error said like below.
2020-06-29 08:57:52.663 2306-2700/com.asset.assettag E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Screenshots Screenshot_2020-06-29-08-21-34-661_com.android.printspooler.jpg: open failed: EACCES (Permission denied)
2020-06-29 08:57:52.664 2306-2700/com.asset.assettag E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
Process: com.asset.assettag, PID: 2306
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.blikoon.qrcodescanner.decode.DecodeImageThread.run(DecodeImageThread.java:29)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
2020-06-29 08:57:52.663 2306-2700/com.asset.assettag E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Screenshots/Screenshot_2020-06-29-08-21-34-661_com.android.printspooler.jpg: open failed: EACCES (Permission denied)
This is my coding
public class ScanActivity extends AppCompatActivity {
private Button button;
private static final int REQUEST_CODE_QR_SCAN = 101;
private final String LOGTAG = "QRCScanner-ScanActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
button = (Button) findViewById(R.id.button_start_scan);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Start the qr scan activity
Intent i = new Intent(ScanActivity.this,QrCodeActivity.class);
startActivityForResult( i,REQUEST_CODE_QR_SCAN);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) {
Log.d(LOGTAG, "COULD NOT GET A GOOD RESULT.");
if (data == null)
return;
//Getting the passed result
String result = data.getStringExtra("com.blikoon.qrcodescanner.error_decoding_image");
if (result != null) {
AlertDialog alertDialog = new AlertDialog.Builder(ScanActivity.this).create();
alertDialog.setTitle("Scan Error");
alertDialog.setMessage("QR Code could not be scanned");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
return;
}
if (requestCode == REQUEST_CODE_QR_SCAN) {
if (data == null)
return;
//Getting the passed result
String result = data.getStringExtra("com.blikoon.qrcodescanner.got_qr_scan_relult");
Log.d(LOGTAG, "Have scan result in your app activity :" + result);
AlertDialog alertDialog = new AlertDialog.Builder(ScanActivity.this).create();
alertDialog.setTitle("Scan result");
alertDialog.setMessage(result);
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
}
This is library coding and problem pin point.
public class DecodeImageThread implements Runnable {
private static final int MAX_PICTURE_PIXEL = 256;
private byte[] mData;
private int mWidth;
private int mHeight;
private String mImgPath;
private DecodeImageCallback mCallback;
public DecodeImageThread(String imgPath, DecodeImageCallback callback) {
this.mImgPath = imgPath;
this.mCallback = callback;
}
@Override
public void run() {
if (null == mData) {
if (!TextUtils.isEmpty(mImgPath)) {
Bitmap bitmap = QrUtils.decodeSampledBitmapFromFile(mImgPath, MAX_PICTURE_PIXEL, MAX_PICTURE_PIXEL);
this.mData = QrUtils.getYUV420sp(bitmap.getWidth(), bitmap.getHeight(), bitmap);
this.mWidth = bitmap.getWidth();
this.mHeight = bitmap.getHeight();
}
}
if (mData == null || mData.length == 0 || mWidth == 0 || mHeight == 0) {
if (null != mCallback) {
mCallback.decodeFail(0, "No image data");
}
return;
}
final Result result = QrUtils.decodeImage(mData, mWidth, mHeight);
if (null != mCallback) {
if (null != result) {
mCallback.decodeSucceed(result);
} else {
mCallback.decodeFail(0, "Decode image failed.");
}
}
}
}
UPDATE METHOD THAT LIBRARY CALL DECODEIMAGETHREAD
protected void onActivityResult(int requestCode, int resultCode, final Intent data) { if (resultCode != RESULT_OK) { return; } switch (requestCode) { case REQUEST_PICTURE: finish(); break; case REQUEST_SYSTEM_PICTURE: Uri uri = data.getData(); String imgPath = getPathFromUri(uri); if (imgPath!=null && !TextUtils.isEmpty(imgPath) &&null != mQrCodeExecutor) { mQrCodeExecutor.execute(new DecodeImageThread(imgPath, mDecodeImageCallback)); } break; } }
Thanks so much for help.