更改Webview页面时如何删除意图组件?

时间:2019-02-21 11:51:10

标签: android webview

我创建了一个像这样的webview应用程序,当我们扫描qrcode或条形码时,这会将intent组件带到MainActivity,然后我想在更改导航栏时删除intent组件。

这是MainActivity,

public class MainActivity extends AppCompatActivity {


private WebView webView;
private CustomWebViewClient webViewClient;



private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
        = new BottomNavigationView.OnNavigationItemSelectedListener() {

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case R.id.btngiris:

                Intent intend = getIntent();
                String pID = getIntent().getStringExtra("ID");
                String pSifre = getIntent().getStringExtra("Sifre");
                String pBarkod = getIntent().getStringExtra("Barkod");


                    if (pID == null) {
                        try {
                            FileInputStream fis_ID = openFileInput("pID");
                            InputStreamReader isr_ID = new InputStreamReader(fis_ID);
                            BufferedReader br_ID = new BufferedReader(isr_ID);
                            pID = br_ID.readLine();
                            fis_ID.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        try {
                            FileInputStream fis_Sifre = openFileInput("pSifre");
                            InputStreamReader isr_Sifre = new InputStreamReader(fis_Sifre);
                            BufferedReader br_Sifre = new BufferedReader(isr_Sifre);
                            pSifre = br_Sifre.readLine();
                            fis_Sifre.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    else {
                        if (pBarkod == null) {
                            webView.loadUrl("http://www.truebilisim.com/myiphone/index.php?id=" + pID + "&sifre=" + pSifre);
                        }
                        else {
                            webView.loadUrl("http://www.truebilisim.com/myiphone/barkodara.php?barkod=" + pBarkod);
                        }
                    }


                return true;
            case R.id.btnayarlar:
                Intent intent = new Intent(getApplicationContext(), AyarlarActivity.class);
                startActivity(intent);
                return true;

            case R.id.btnbarkod:
                Intent indent = new Intent(getApplicationContext(), BarkodActivity.class);
                startActivity(indent);
                return true;
        }
        return false;
    }
};

private class CustomWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // Bu method açılan sayfa içinden başka linklere tıklandığında açılmasına yarıyor.
        //Bu methodu override etmez yada edip içini boş bırakırsanız ilk url den açılan sayfa dışında başka sayfaya geçiş yapamaz

        view.loadUrl(url);//yeni tıklanan url i açıyor
        return true;
    }
}

@Override
protected void onSaveInstanceState(Bundle outState ){
    super.onSaveInstanceState(outState);
    webView.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
    super.onRestoreInstanceState(savedInstanceState);
    webView.restoreState(savedInstanceState);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    webView = findViewById(R.id.webView);
    webViewClient = new CustomWebViewClient();
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(webViewClient);

    if (savedInstanceState != null)
        ((WebView)findViewById(R.id.webView)).restoreState(savedInstanceState);
    else {

        Intent intend = getIntent();
        String pID = getIntent().getStringExtra("ID");
        String pSifre = getIntent().getStringExtra("Sifre");

        if (pID==null){
            try{
                FileInputStream fis_ID = openFileInput("pID");
                InputStreamReader isr_ID = new InputStreamReader(fis_ID);
                BufferedReader br_ID = new BufferedReader(isr_ID);
                pID = (String) br_ID.readLine();
                fis_ID.close();
            }catch(Exception e){
                e.printStackTrace(); }

            try{
                FileInputStream fis_Sifre = openFileInput("pSifre");
                InputStreamReader isr_Sifre = new InputStreamReader(fis_Sifre);
                BufferedReader br_Sifre = new BufferedReader(isr_Sifre);
                pSifre = br_Sifre.readLine();
                fis_Sifre.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }

        webView.loadUrl("http://www.truebilisim.com/myiphone/index.php?id="+pID+"&sifre="+pSifre);
    //    webView.loadUrl("http://www.truebilisim.com/myiphone/barkodara.php?barkod="+pBarkod);
    }

    BottomNavigationView navigation = findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

}

}

当我扫描条形码时,它会看到pBarkod意图组件,向我显示Web视图,因此我想在更改导航栏时删除pBarkod。因为我想显示此网络视图,所以

 webView.loadUrl("http://www.truebilisim.com/myiphone/index.php?id=" + pID + "&sifre=" + pSifre);

你能告诉我我怎么做吗?

0 个答案:

没有答案