jeudi 2 novembre 2017

open activity before checking url parameters in android

i am new in android. In my application i need to check the url and if find some parameter then the url will open in a activity call playActivity.class otherwise it will open the url in default browser the parameter is ad=no. I need to check the url if here a GET request with ad=no I tried code below

        Uri uri = Uri.parse(url);
        String vid_id = uri.getQueryParameter("id");
        String ads = uri.getQueryParameter("ad");
        Toast.makeText(MainActivity.this,ads,Toast.LENGTH_SHORT).show();

        if(ads=="no") {
                Toast.makeText(MainActivity.this, "Videoclick", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(MainActivity.this, playActivity.class);
                intent.putExtra("id", vid_id);
                intent.putExtra("url", url);
                startActivity(intent);
            }if(ads!="no"){

                Toast.makeText(MainActivity.this,"AdClick",Toast.LENGTH_SHORT).show();
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);
            }

for testing purpose i create a Toast with value of ads String. Wile the toast give me no result so it should open the url in playActivity.class but it open the url in my browser. I think something I missed in if condition.Please someone help.

Aucun commentaire:

Enregistrer un commentaire