Android App click button launcher navigation directly

Android App click button to launcher navigation directly

How to create an Android with Android Studio click button to launcher navigation

  1. Download and install Android Studio.
  2. Start a new Android Studio project.
  3. Select Empty Activity, with Jave.
The code below have three button for New York airports.
activity_main.xml
===============

<?xml version="1.0" encoding="utf-8"?><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:id="@+id/Backgroud"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#2A3675"    tools:context=".MainActivity">
    <Button        android:id="@+id/button_ewr"        android:layout_width="0dp"        android:layout_height="96dp"        android:layout_marginStart="32dp"        android:layout_marginLeft="32dp"        android:layout_marginEnd="32dp"        android:layout_marginRight="32dp"        android:layout_marginBottom="64dp"        android:clickable="true"        android:focusable="true"        android:onClick="goToewr"        android:text="@string/newark"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintHorizontal_bias="0.0"        app:layout_constraintStart_toStartOf="parent" />
    <Button        android:id="@+id/button_jfk"        android:layout_width="0dp"        android:layout_height="96dp"        android:layout_marginStart="32dp"        android:layout_marginLeft="32dp"        android:layout_marginEnd="32dp"        android:layout_marginRight="32dp"        android:layout_marginBottom="64dp"        android:clickable="true"        android:focusable="true"        android:onClick="goTolga"        android:text="@string/jfk"        app:layout_constraintBottom_toTopOf="@+id/button_ewr"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintHorizontal_bias="1.0"        app:layout_constraintStart_toStartOf="parent" />
    <Button        android:id="@+id/button_lga"        android:layout_width="0dp"        android:layout_height="96dp"        android:layout_marginStart="32dp"        android:layout_marginLeft="32dp"        android:layout_marginEnd="32dp"        android:layout_marginRight="32dp"        android:layout_marginBottom="64dp"        android:autoLink="web"        android:clickable="true"        android:focusable="true"        android:onClick="goTojfk"        android:text="@string/lga"        app:layout_constraintBottom_toTopOf="@+id/button_jfk"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent" /></androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
=============


package com.xyz.navigation;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;
public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }
    public void goTojfk (View view) {
        goToUrl ( "google.navigation:q=JFK+Terminal+4,+Queens,+NY");    }

    public void goTolga (View view) {
        goToUrl ( "google.navigation:q=LaGuardia+Airport+(LGA),+New+York,+NY+11371");    }

    public void goToewr (View view) {
        goToUrl ( "google.navigation:q=Newark+Liberty+International+Airport+(EWR),+Brewster+Road,+Newark,+NJ");    }

    private void goToUrl (String url) {
        Uri uriUrl = Uri.parse(url);        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);        startActivity(launchBrowser);    }
}

Comments

Popular posts from this blog

Extracting and using a modified VMWare Player BIOS or UEFI firmware

Activate Synology Active Backup for Business for DSM 6

Windows 11 internet/account bypass