0% found this document useful (0 votes)
11 views

EXP 18

The document contains code snippets for three Android applications: a navigation app that opens a URL or dials a phone number based on user input, a factorial calculator that computes the factorial of a number entered by the user, and associated XML layout files for user interfaces. Each app features an EditText for input and buttons for actions, with appropriate intents to handle user interactions. The code demonstrates basic Android development practices, including activity lifecycle management and user input handling.

Uploaded by

sawantkrish562
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

EXP 18

The document contains code snippets for three Android applications: a navigation app that opens a URL or dials a phone number based on user input, a factorial calculator that computes the factorial of a number entered by the user, and associated XML layout files for user interfaces. Each app features an EditText for input and buttons for actions, with appropriate intents to handle user interactions. The code demonstrates basic Android development practices, including activity lifecycle management and user input handling.

Uploaded by

sawantkrish562
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

EXP 18 Intent i= new Intent(Intent.

ACTION_VIEW,uri);
startActivity(i);
<?xml version="1.0" encoding="utf-8"?> }
<LinearLayout });
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="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content"
tools:context=".MainActivity">

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text=" " />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Navigate" />
</LinearLayout>

package com.example.navigate;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


EditText e1;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.button);
e1 = (EditText)findViewById(R.id.editText);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s1= e1.getText().toString();
Uri uri=Uri.parse("https://" + s1);
EXP 18.2 startActivity(i);
}
<?xml version="1.0" encoding="utf-8"?> else
<LinearLayout {
xmlns:android="http://schemas.android.com/apk/res/ Uri u = Uri.parse("tel:" +
android" e1.getText().toString());
xmlns:app="http://schemas.android.com/apk/res- Intent i = new Intent(Intent.ACTION_DIAL,u);
auto" startActivity(i);
xmlns:tools="http://schemas.android.com/tools" }
android:layout_width="match_parent" }
android:layout_height="match_parent" });
android:orientation="vertical" }
tools:context=".MainActivity"> }

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" AndroidManifest.xml
android:ems="10" <?xml version="1.0" encoding="utf-8"?>
android:inputType="phone" /> <manifest
xmlns:android="http://schemas.android.com/apk/res/
<Button android"
android:id="@+id/button" package="com.example.dialer">
android:layout_width="match_parent" <uses-permission
android:layout_height="wrap_content" android:name="android.permission.CALL_PHONE"/>
android:text="Button" /> <application
android:allowBackup="true"
</LinearLayout> android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

package com.example.dialer; android:roundIcon="@mipmap/ic_launcher_round"


android:supportsRtl="true"
import androidx.appcompat.app.AppCompatActivity; android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
import android.content.Intent; <intent-filter>
import android.net.Uri; <action
import android.os.Bundle; android:name="android.intent.action.MAIN" />
import android.text.TextUtils;
import android.view.View; <category
import android.widget.Button; android:name="android.intent.category.LAUNCHER" />
import android.widget.EditText; </intent-filter>
</activity>
public class MainActivity extends AppCompatActivity { </application>
Button b1;
EditText e1; </manifest>
String s1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.button);
e1 = (EditText)findViewById(R.id.editText);
s1=e1.getText().toString();
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(s1=="") {
Intent i = new Intent(Intent.ACTION_DIAL);
EXP 18.3

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity">

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Number"/>
<TableRow android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="15dp" >
<Button
android:id="@+id/button"
android:layout_marginRight="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Factorial" />

<Button
android:id="@+id/button2"
android:layout_marginLeft="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear" />
</TableRow>
</LinearLayout>

package com.example.factorial;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


EditText e1;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) { android:layout_width="match_parent"
super.onCreate(savedInstanceState); android:layout_height="wrap_content"
setContentView(R.layout.activity_main); android:text="Button" />
e1 = (EditText)findViewById(R.id.editText2); </LinearLayout>
b1 = (Button)findViewById(R.id.button);
b2 = (Button)findViewById(R.id.button2); CalcFacto.java
b2.setOnClickListener(new View.OnClickListener() { package com.example.factorial;
@Override
public void onClick(View v) { import androidx.appcompat.app.AppCompatActivity;
e1.setText("");
} import android.content.Intent;
}); import android.os.Bundle;
import android.view.View;
b1.setOnClickListener(new View.OnClickListener() { import android.widget.Button;
@Override import android.widget.TextView;
public void onClick(View v) { import android.widget.Toast;
String ch=e1.getText().toString();
if(!ch.isEmpty()) { public class CalcFacto extends AppCompatActivity {
Intent i = new Intent(MainActivity.this, TextView t1;
CalcFacto.class); Button b3;
String x = e1.getText().toString(); @Override
i.putExtra("Number", x); protected void onCreate(Bundle savedInstanceState) {
startActivity(i); super.onCreate(savedInstanceState);
} setContentView(R.layout.activity_calc_facto);
else t1 = (TextView)findViewById(R.id.textView);
{ b3 = (Button)findViewById(R.id.button4);
Intent i2 = getIntent();
Toast.makeText(getApplicationContext(),"Invalid String y = i2.getStringExtra("Number");
number ",Toast.LENGTH_LONG).show(); int num = Integer.parseInt(y);
} int fact =1;
} while(num>0)
}); {
} fact = fact * num;
} num--;
}
activity_calc_facto.xml t1.setText("The Factorial of Entered Number is
"+Integer.toString(fact));
<?xml version="1.0" encoding="utf-8"?> b3.setOnClickListener(new View.OnClickListener() {
<LinearLayout @Override
xmlns:android="http://schemas.android.com/apk/res/ public void onClick(View v) {
android" Intent i3 = new
xmlns:app="http://schemas.android.com/apk/res- Intent(CalcFacto.this,MainActivity.class);
auto" Toast.makeText(getApplicationContext(),"Going
xmlns:tools="http://schemas.android.com/tools" Back to main page", Toast.LENGTH_LONG).show();
android:layout_width="match_parent" startActivity(i3);
android:layout_height="match_parent" try {
android:orientation="vertical"
tools:context=".CalcFacto"> Thread.sleep(2500);
}
catch (Exception ex)
<TextView {}
android:id="@+id/textView" }
android:layout_width="match_parent" });
android:layout_height="wrap_content"
android:text="TextView" />

<Button
android:id="@+id/button4"
}

You might also like