0

hello i have created the webview in mail activity of the android studio and now i am in scanner activity and when the APP scans any QR code having the link it just writs the link but what i want to do is to open the link in the web view already created in mail activity.

let me place my scanner file here

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scanner);
        scannView = findViewById(R.id.scannerView);
        codeScanner = new CodeScanner(this,scannView);
        resultData = findViewById(R.id.resultsOfQr);

        codeScanner.setDecodeCallback(new DecodeCallback() {
            @Override
            public void onDecoded(@NonNull final Result result) {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        resultData.setText(result.getText());
//                        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(result.getText()));
//                        startActivity(browserIntent);

                        Intent intent = new Intent(getBaseContext(), MainActivity.class);
                        intent.putExtra("myurl1", result.getText());
                        startActivity(intent);

                    }
                });

            }
        });


        scannView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                codeScanner.startPreview();
            }
        });
    }
    
    
            scannView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    codeScanner.startPreview();
                }
            });
        }

WEBVIEW in Mailactivity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    scanBtn = findViewById(R.id.scanBtn);

    MywebView = (WebView) findViewById(R.id.view2);
    WebSettings webSettings = MywebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    MywebView.loadUrl("https://google.com/APP/");

    MywebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains("tel:")) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse(url));
                startActivity(intent);
                return true;
            }else{
                return false;
            }
        }
    });
    scanBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(getApplicationContext(),Scanner.class));
        }
    });

    String myrul = getIntent().getStringExtra("myurl1");
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            MywebView.loadUrl(myrul);
        }
    });

}

Any idea how can i do this, any help is appreciated. Thankx

1 Answers1

0

In you CodeScanner Callback Load the WebView

runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    resultData.setText(result.getText());
                    MywebView.loadUrl(result.getText());
                }
            });
Atick Faisal
  • 1,086
  • 1
  • 6
  • 13
  • if i create the variable above then it crashes ! –  Sep 22 '20 at 02:17
  • If you WebView and CodeScanner are in different activities then you can use Intent to pass the result from CodeScanner to MainActivity and then load the WebView with it. [Passing Data Between Activities](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Atick Faisal Sep 23 '20 at 06:30
  • i really appreciate your help Faisal, but as i am very new to APPs i have less info to do that even after all this really usefull links. i updated the code and i think i can pass the intent now but the APP crashes all the time now ? could take a quick look anytime plx ? –  Sep 24 '20 at 06:15