Vishal Yadav 1000017720
Vishal Yadav 1000017720
Vishal Yadav 1000017720
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
Button bt1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} else {
tv1.setText(et1.getText().toString());
tv2.setText(et2.getText().toString());
package com.example.calculator;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextNumber1 = findViewById(R.id.editTextNumber1);
editTextNumber2 = findViewById(R.id.editTextNumber2);
buttonAdd = findViewById(R.id.buttonAdd);
buttonSubtract = findViewById(R.id.buttonSubtract);
buttonMultiply = findViewById(R.id.buttonMultiply);
buttonDivide = findViewById(R.id.buttonDivide);
textViewResult = findViewById(R.id.textViewResult);
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
performOperation('+');
});
buttonSubtract.setOnClickListener(new View.OnClickListener() {
@Override
performOperation('-');
});
buttonMultiply.setOnClickListener(new View.OnClickListener() {
@Override
performOperation('*');
});
buttonDivide.setOnClickListener(new View.OnClickListener() {
@Override
});
double result = 0;
switch (operation) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
if (num2 != 0) {
} else {
break;
3. Create an Android application that takes input from the user and displays the
1.MainAcitivity.java
package com.example.sahilkumar;
import android.content.Intent;
import android.os.Bundle; import android.view.View; import
Button buttonSubmit;
@Override
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
editTextFirstName = findViewById(R.id.inputeditTextFirstName);
= findViewById(R.id.submitButton);
buttonSubmit.setOnClickListener(new View.OnClickListener() {
@Override
});
2.MainAcitivity2.java
package com.example.sahilkumar; import android.content.Intent; import android.os.Bundle;
import android.widget.TextView;
import
androidx.appcompat.app.AppCompatActivity;
TextView textViewDisplay;
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2);
}}} }
4. Create an Android application that demonstrates the methods of the lifecycle
of an Android activity.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast toast = Toast.makeText(getApplicationContext(), "onCreate Called",
Toast.LENGTH_LONG).show();
super.onStart();
@Override
super.onRestart();
super.onPause();
super.onResume();
super.onDestroy();
}}
5. Develop an android application for making phone calls using phone dialer.
// MainActivity.kt
package com.example.myapplication;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNumberEditText = findViewById(R.id.mobile);
}
public void makePhoneCall(View view) {
if (!phoneNumber.isEmpty()) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) !=
PackageManager.PERMISSION_GRANTED) {
} else {
} else {
@Override
if (requestCode == REQUEST_CALL_PHONE) {
makePhoneCall(findViewById(android.R.id.content));
} else {
Toast.makeText(this, "Permission DENIED", Toast.LENGTH_SHORT).show();
App.
package example.javatpoint.com.optionmenu;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setSupportActionBar(toolbar);
@Override
// Inflate the menu; this adds items to the action bar if it is present
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
@Override
int id = item.getItemId();
switch (id){
case R.id.item1:
Toast.makeText(getApplicationContext(),"Item 1 Selected",Toast.LENGTH_LONG).show();
return true;
case R.id.item2:
Toast.makeText(getApplicationContext(),"Item 2 Selected",Toast.LENGTH_LONG).show();
return true;
case R.id.item3:
Toast.makeText(getApplicationContext(),"Item 3 Selected",Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}}}
7. Develop an Android application that plays a media file.
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.concurrent.TimeUnit;
public class MainActivity extends Activity {
private Button b1,b2,b3,b4;
private ImageView iv;
private MediaPlayer mediaPlayer;
private double startTime = 0;
private double finalTime = 0;
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button)findViewById(R.id.button3);
b4 = (Button)findViewById(R.id.button4);
iv = (ImageView)findViewById(R.id.imageView);
tx1 = (TextView)findViewById(R.id.textView2);
tx2 = (TextView)findViewById(R.id.textView3);
tx3 = (TextView)findViewById(R.id.textView4);
tx3.setText("Song.mp3");
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Playing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.start();
finalTime = mediaPlayer.getDuration();
startTime = mediaPlayer.getCurrentPosition();
if (oneTimeOnly == 0) {
seekbar.setMax((int) finalTime);
oneTimeOnly = 1;
}
seekbar.setProgress((int)startTime);
myHandler.postDelayed(UpdateSongTime,100);
b2.setEnabled(true);
b3.setEnabled(false);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Pausing
sound",Toast.LENGTH_SHORT).show();
mediaPlayer.pause();
b2.setEnabled(false);
b3.setEnabled(true);
}
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int temp = (int)startTime;
if((temp+forwardTime)<=finalTime){
startTime = startTime + forwardTime;
mediaPlayer.seekTo((int) startTime);
Toast.makeText(getApplicationContext(),"You have Jumped forward 5
seconds",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),"Cannot jump forward 5
seconds",Toast.LENGTH_SHORT).show();
}
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int temp = (int)startTime;
if((temp-backwardTime)>0){
startTime = startTime - backwardTime;
mediaPlayer.seekTo((int) startTime);
Toast.makeText(getApplicationContext(),"You have Jumped backward 5
seconds",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),"Cannot jump backward 5
seconds",Toast.LENGTH_SHORT).show();
}
}
});
}
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.ListView
import androidx.appcompat.app.AppCompatActivity
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
listView = findViewById(R.id.listView)
addButton = findViewById(R.id.addButton)
// Create an ArrayAdapter
listView.adapter = adapter
for (i in 1..5) {
adapter.add("Item $i")
addButton.setOnClickListener {
adapter.add("Item $itemCount")
}