package com.indeedinspiring.androidworkshop_practice;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import static android.Manifest.permission.CALL_PHONE;
import static android.Manifest.permission.CAMERA;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Button openbrower, opencall, opencontact, openCamera;

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

}

private void initListeners() {
openbrower.setOnClickListener(this);
opencall.setOnClickListener(this);
openCamera.setOnClickListener(this);
opencontact.setOnClickListener(this);
}

private void initView() {
openbrower = findViewById(R.id.openbrower);
opencall = findViewById(R.id.opencall);
openCamera = findViewById(R.id.opencamera);
opencontact = findViewById(R.id.opencontact);
}

@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(View view) {

switch (view.getId()) {

case R.id.openbrower:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“https://google.com”));
startActivity(intent);
break;

case R.id.opencall:
Intent i = new Intent(Intent.ACTION_CALL);
i.setData(Uri.parse(“tel:0612312312”));
if (ContextCompat.checkSelfPermission(getApplicationContext(), CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
startActivity(i);
} else {
requestPermissions(new String[]{CALL_PHONE}, 1);
}
break;

case R.id.opencontact:
Intent i1 = new Intent(Intent.ACTION_VIEW);
i1.setData(Uri.parse(“content://contacts/people/”));
startActivity(i1);
break;

case R.id.opencamera:
Intent intent1 = new Intent(“android.media.action.IMAGE_CAPTURE”);

if (ContextCompat.checkSelfPermission(getApplicationContext(), CAMERA) == PackageManager.PERMISSION_GRANTED) {
startActivity(intent1);
} else {
requestPermissions(new String[]{CAMERA}, 1);
}
startActivity(intent1);
break;

}
}
}

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.indeedinspiring.androidworkshop_practice”>

 

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

<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” />
<action android:name=”android.intent.action.VIEW”/>
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>

</manifest>

<?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/linearLayout”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”.MainActivity”>

 

<Button
android:id=”@+id/openbrower”
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_marginStart=”16dp”
android:layout_marginLeft=”16dp”
android:layout_marginEnd=”16dp”
android:layout_marginRight=”16dp”
android:text=”open Web”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintHorizontal_bias=”0.0″
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintVertical_bias=”0.077″ />

<Button
android:id=”@+id/opencall”
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_marginStart=”16dp”
android:layout_marginLeft=”16dp”
android:layout_marginEnd=”16dp”
android:layout_marginRight=”16dp”
android:text=”open Call”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintHorizontal_bias=”0.0″
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintVertical_bias=”0.172″ />

<Button
android:id=”@+id/opencontact”
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_marginStart=”16dp”
android:layout_marginLeft=”16dp”
android:layout_marginEnd=”16dp”
android:layout_marginRight=”16dp”
android:text=”Open Contact”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintHorizontal_bias=”0.0″
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintVertical_bias=”0.278″ />

<Button
android:id=”@+id/opencamera”
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_marginStart=”16dp”
android:layout_marginLeft=”16dp”
android:layout_marginEnd=”16dp”
android:layout_marginRight=”16dp”
android:text=”Open Camera”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintHorizontal_bias=”0.0″
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toTopOf=”parent”
app:layout_constraintVertical_bias=”0.393″ />

 

</androidx.constraintlayout.widget.ConstraintLayout>

Click here for code files: https://drive.google.com/open?id=1m9cBwe9iFSpI47WL9KAuOfhCLEVJEJQI