Question

Using Android Studio Java, create a program which has two functions: Function1: has a text field...

Using Android Studio Java, create a program which has two functions:

Function1: has a text field and a button to invoke "Function 2"

Function 2: process the data entered in the text field on Function 1.

  • If data in text field starts with "url:" (for e.g. url:www.google.com or url:www,palomar.edu), display the URL in the default browser.
  • If data in text field starts with "phone:" ( for e.g. "phone:7607441150"), call the phone number using the dialer application.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.webcall">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

activity_main.xml

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/parserField"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="150dp"
        android:layout_marginEnd="8dp"
        android:ems="10"
        android:hint="Enter URL/Phone Number"
        android:inputType="textPersonName"
        android:padding="16dp"
        android:textAlignment="center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/submitButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:backgroundTint="@color/colorAccent"
        android:padding="16dp"
        android:text="Submit"
        android:textColor="@android:color/white"
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/parserField" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private EditText parserField;
    private Button submitButton;

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

        function1();
    }

    private void function1()
    {
        parserField = (EditText) findViewById(R.id.parserField);
        submitButton = (Button) findViewById(R.id.submitButton);

        submitButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String text = parserField.getText().toString();
                function2(text);
            }
        });
    }

    private void function2(String text)
    {
        String[] data = text.split(":");
        String indicator = data[0];     // url or phone
        String value = data[1];

        switch (indicator)
        {
            case "url":
            {
                if (!value.startsWith("http://") && !value.startsWith("https://"))
                    value = "http://" + value;

                Uri url = Uri.parse(value);

                Intent browserIntent = new Intent(Intent.ACTION_VIEW, url);
                if (browserIntent.resolveActivity(getPackageManager()) != null) {
                    startActivity(browserIntent);
                }
                break;
            }

            case "phone":
            {
                if(!value.startsWith("tel:"))
                    value = "tel:" + value.trim();

                Uri callNumber = Uri.parse(value);
                Intent callerIntent = new Intent(Intent.ACTION_DIAL);
                callerIntent.setData(callNumber);
                startActivity(callerIntent);
                break;
            }
        }
    }
}

**********************************************************************************************************************************************

Add a comment
Know the answer?
Add Answer to:
Using Android Studio Java, create a program which has two functions: Function1: has a text field...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows...

    Android Problem Using JAVA Problem: You need to create an app on Android Studios that allows users to register and login into the system. The focus of this project is for you to create an app with several activities and has data validation. You should have for your app: A welcome screen (splash screen) with your app name and a picture. You should then move to a screen that asks the user for either to log in or to register....

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • Call this program StackTester (this will contain the main method). Create three other classes called StackGUI,...

    Call this program StackTester (this will contain the main method). Create three other classes called StackGUI, StackADT, and ArrayStack, respectively (there will be no main method within these classes). In java use a text field to enter a string of words , use a button to initiate the translation of a users string of words to be backwards. Instead of pushing a space (i.e. the space between two words) onto the stack, push the character ‘*’. Use another text field...

  • 1. Create an app with a button and a text field. Display the current count in...

    1. Create an app with a button and a text field. Display the current count in the text field (display 0 when the app loads). CODE EACH OF THESE SUB QUESTIONS AS SEPARATE APPS! a. Count up to 20, then automatically start back at 1 (instead of reaching 21). b. Count up by one for each button press for the first 10 presses, then count up by 2 for the next 10 presses, 3 for the next 10, and so...

  • C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...

    C++ Visul Studio Create a class named Vehicle. The class has the following five member variables: • Vehicle Name • Vehicle number • Sale Tax • Unit price • Total price Include set (mutator) and get (accessor) functions for each field except the total price field. The set function prompt the user for values for each field. This class also needs a function named computePrice() to compute the total price (quantity times unit price + salesTax) and a function to...

  • *Use Java to create this program* For this assignment, you will be building a Favorite Songs...

    *Use Java to create this program* For this assignment, you will be building a Favorite Songs application. The application should have a list with the items displayed, a textbox for adding new items to the list, and four buttons: Add, Remove, Load, and Save. The Add button takes the contents of the text field (textbox) and adds the item in it to the list. Your code must trim the whitespace in front of or at the end of the input...

  • This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display...

    This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display a weather forecast for the user’s current location Create the app titled Weather Forecaster The first screen will have a textbox for the user to enter a zip code and a button to submit When the user enters the zip code and clicks the button, the app will navigate to the weather forecast screen. The weather forecast screen will show the current weather for...

  • (Android Studio) Create a camera app that allows the user to upload a picture from their...

    (Android Studio) Create a camera app that allows the user to upload a picture from their phone camera gallery, see the picture via summary page, and edit the picture as well. Clicking on "Insert picture here from camera photo gallery" in the add page will allow the user to upload a picture from their existing camera photo gallery on their phone. The user can choose where to save the picture, starting with Picture 1-5. Once they choose where to save...

  • JAVA SOLUTION This lab has four parts: Create a window. Create 5 buttons in that window....

    JAVA SOLUTION This lab has four parts: Create a window. Create 5 buttons in that window. Create an event when a button is pushed. Create an event listener that will respond to the button being pushed event. Task 1 – Create a Window For Java: Please ensure that the following import statements are used: import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.text.Text; import javafx.event.EventHandler; import javafx.scene.input.MouseEvent; Next, ensure that there is a main method which is...

  • JAVASCRIPT Write a GUI application that has three labels, two text fields, and two buttons (with...

    JAVASCRIPT Write a GUI application that has three labels, two text fields, and two buttons (with the titles Name and Age). When the program starts the user will enter his/her first name in the first text field and his age in the second text field. When the user clicks the Name button, the first name entered by the user will be displayed as a separate label with the words "CSC210 student at the back of it. When the user clicks...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT