Java中的Firebase数据库参考URL有效性检查逻辑

时间:2019-04-21 15:26:38

标签: java firebase firebase-realtime-database

我想区分有效URL和无效URL(没有意义)。这样我就可以相应地编写逻辑代码。

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);

                }
            });
 }

它应该产生的输出是


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

0 个答案:

没有答案