Implicit Intent (Running an existing application)

You can run an existing application installed on your Android device from an application. In general, information such as class name is unknown in the installed application, so implicit Intent is used.

Web browser execution

Here, as an example, create an application that displays the page of the specified URL using a Web browser.

Below is the code for the main Activity.

        //Get the button
        Button button = (Button)findViewById(R.id.button);

        //Get a string from EditText
        EditText editText = (EditText)findViewById(R.id.editText);
        final String text = editText.getText().toString();

        //What to do when the button is clicked
        button.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                //Create a Uri type variable from a string
                Uri uri = Uri.parse(text);

                //Set Activity and uri to be executed to Intent
                //If you want to display something using a URI, Intent.ACTION_Use VIEW
                Intent intent = new Intent(Intent.ACTION_VIEW,uri);

                //Execute Activity
                startActivity(intent);
            }
        });

The point is the intent constructor The character string for determining the Activity to be executed in the first argument, The uri is set in the second argument. The ACTION_VIEW used this time starts the following application according to the type of uri.

URI type Application to be executed
http: Web browser
https: Web browser
tel Application to make a call
mailto: Email application

GitHub link

https://github.com/tagfa/MyImplicitMainActivity02

Recommended Posts

Implicit Intent (Running an existing application)
Rails6 I tried to introduce Docker to an existing application
[Rails] Create an application
[Swift] Trajectory until adding WidgetKit to an existing application
How to create an application