-1

I'm trying to store info from Qr code on Firebase. I want to store the Url that I get from the Qr code to Firebase. I get "No content provider:" and "could not locate file for uploading:" error in logcat. How do I add Content Provider So I can upload the file.

This is my code so far. I use Zxing for the Qr code.

button.setOnClickListener(new View.OnClickListener() {





        public void onClick(View v) {
            IntentIntegrator intentIntegrator = new IntentIntegrator(
                    main.this
            );

            intentIntegrator.setPrompt("Scan Qr Code, for light use volume up and down");

            intentIntegrator.setBeepEnabled(false);

            intentIntegrator.setOrientationLocked(true);

            intentIntegrator.setCaptureActivity(Capture.class);

            intentIntegrator.initiateScan();


        }
    });

}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);

    if(result != null) {
        if(result.getContents() == null) {
            Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
        } else {

            String Contents = result.getContents();

            imageUri10 = Uri.parse(Contents);
      
            // Toast.makeText(this, Contents, Toast.LENGTH_LONG).show();




            uploadImageToFirebase5();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}



private void uploadImageToFirebase5() {

    StorageReference fileRef = storageReference.child("profile7.jpg");
    fileRef.putFile(imageUri10);
}
  • 1
    Show the code where you are trying to save the url to firebase – SABANTO Apr 17 '21 at 15:14
  • The thing is that the url is save inside a IntentResult and I can't pass it to firebase. It needs to be an uri or string. StorageReference dbb = storageReference.child("profile7.jpg"); dbb.putFile(intentResult.getContents()); this wont work because intent Result is not an uri. But the string is inside the intentResult. – Ólafur Ingi Apr 18 '21 at 00:31
  • I did this but it does not add the url to firebase storage = FirebaseStorage.getInstance(); storageReference = FirebaseStorage.getInstance().getReference(); StorageReference dbb = storageReference.child("profile7.jpg"); dbb.putFile(Uri.parse(intentResult.getContents())); – Ólafur Ingi Apr 18 '21 at 00:45
  • Tried this but not working String Send = intentResult.getContents(); storage = FirebaseStorage.getInstance(); storageReference = FirebaseStorage.getInstance().getReference(); StorageReference dbb = storageReference.child("profile7.jpg"); dbb.putFile(Uri.parse(Send)); – Ólafur Ingi Apr 18 '21 at 00:53
  • Updated my answer, try it and get back to me. – SABANTO Apr 18 '21 at 05:08
  • Now I did this: String Contents = result.getContents(); imageUri10 = Uri.parse(Contents); And it now gives me: "No content provider:" error in logcat. – Ólafur Ingi Apr 19 '21 at 05:00

2 Answers2

0

To get URI try this

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
  if(result.getContents() == null) {
    Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
   } else {
    //get uri here
       }
   } else {
         super.onActivityResult(requestCode, resultCode, data);
       }
   }

In the activity result.

Refer to this article on how to read and write data to firebase. You can also read this article. If you have read, and attempted to write data to firebase then, you can post what you have done and you will be assisted.

Also suggest this solution, an api built on top of zxing, makes things a lot simpler.

SABANTO
  • 1,316
  • 9
  • 24
  • Thank you for the articles have read them but the issue is that I need to convert the IntentResult into string or uri to pass it into the firebase storage. I have tryied this but it wont work StorageReference dbb = storageReference.child("profile7.jpg"); dbb.putFile(intentResult.getContents()); intentResult is not an uri – Ólafur Ingi Apr 18 '21 at 00:44
  • I did this but the app scans the code but does nothing. storage = FirebaseStorage.getInstance(); storageReference = FirebaseStorage.getInstance().getReference(); StorageReference dbb = storageReference.child("profile7.jpg"); dbb.putFile(Uri.parse(intentResult.getContents())); – Ólafur Ingi Apr 18 '21 at 00:45
  • Tried this but not working. String Send = intentResult.getContents(); storage = FirebaseStorage.getInstance(); storageReference = FirebaseStorage.getInstance().getReference(); StorageReference dbb = storageReference.child("profile7.jpg"); dbb.putFile(Uri.parse(Send)); – Ólafur Ingi Apr 18 '21 at 00:53
  • Oh, ok I thought you already had the url, and you just need to save. Let me update my answer – SABANTO Apr 18 '21 at 05:00
  • Hey Sabanto the YOUR_CODE does not seem to work – Ólafur Ingi Apr 18 '21 at 05:35
  • YOUR_CODE is your code, as in the code you passed startActivityforresult. If you didnt pass any value, remove the requestCode bit in if statement – SABANTO Apr 18 '21 at 05:44
  • This is what I have now, now it just crashes. – Ólafur Ingi Apr 18 '21 at 05:54
  • Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); IntentResult intentResult = IntentIntegrator.parseActivityResult( requestCode, resultCode, data ); if (resultCode == RESULT_OK) { Uri uri = data.getData(); StorageReference fileRef = storageReference.child("profile7.jpg"); fileRef.putFile(imageUri1) – Ólafur Ingi Apr 18 '21 at 05:55
  • Check the logcat for why it crashed – SABANTO Apr 18 '21 at 05:56
  • Updated my answer try it – SABANTO Apr 18 '21 at 06:01
  • uri cannot be null – Ólafur Ingi Apr 18 '21 at 06:28
  • Failure delivering result ResultInfo{who=null, request=49374, result=-1, data=Intent { act=com.google.zxing.client.android.SCAN flg=0x80000 (has extras) }} to activity {com.example.on/com.example.on.main}: java.lang.IllegalArgumentException: uri cannot be null – Ólafur Ingi Apr 18 '21 at 06:29
  • The uri is not getting the data – Ólafur Ingi Apr 18 '21 at 06:31
  • Now I did this: String Contents = result.getContents(); imageUri10 = Uri.parse(Contents); And it now gives me: "No content provider:" error in logcat. – Ólafur Ingi Apr 19 '21 at 05:00
0

First add the dependencies to the project for Firestore:

api 'com.google.firebase:firebase-firestore:22.1.2'

Next access a Cloud Firestore instance from your Activity:

FirebaseFirestore db = FirebaseFirestore.getInstance();

You can save your data on Firebase Firestore like this:

Map<String, Object> myCode = new HashMap<>();
myCode .put("qr_url", "PUT THE QR CODE URL IN HERE");

db.collection("codes").document("PUT THE QR CODE DOCUMENT NAME HERE")
        .set(myCode)
        .addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                Log.d(TAG, "Document successfully written!");
            }
        })
        .addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "Error writing document", e);
            }
        });
user14678216
  • 2,886
  • 2
  • 16
  • 37