I want to distinguish between valid and invalid URL (which makes no sense). So that I could write my logic code accordingly.

protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        final IntentResult result=IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
        address=result.getContents();
        convertToAddress(result.getContents());
 }

//As a parameter we are receiving URL similar to https://myapp-17a2f.firebaseio.com/55dd5vf78rv12vrw6w59w1aa0dhjm
public void convertToAddress(String scannedID){

        firebaseAuth=FirebaseAuth.getInstance();
        firebaseDatabase=FirebaseDatabase.getInstance();
        DatabaseReference databaseReference=firebaseDatabase.getReference(scannedID);
//Here I need the logic to check whether databaseReference variable got valid URL or invalid URL
        Log.e(TAG,"ConvertToAddress: Address is "+ databaseReference.toString());
        databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
             //Code Goes here

          }
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
                    Toast.makeText(ScanCodeActivity.this,databaseError.getCode(),Toast.LENGTH_SHORT);

                }
            });
 }

The output it should produce is


if(logic to check valid URL) {
     Toast("This URL is valid");
} else{
     Toast("This URL is invalid");
}

0 Answers