Suppose you own a business and for its marketing you create an app which has all the details about the business such as product info, address and contact number. Now if the customer wants to call you via your contact number, he/she will expect a simple and quick way to dial the number.
In our app, we will be creating just one click option to take the user to dial a call!
--------------------------------- dial_activity.xml ------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#983428"
android:gravity="center"
android:weightSum="5">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:textSize="38sp"
android:textColor="#ffffff"
android:gravity="center"
android:text="Bruno Chocolates!"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:src="@drawable/chocolate_box"/>
<Button
android:onClick="dialCall"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#be7e3e"
android:gravity="center"
android:textSize="25sp"
android:textColor="#ffffff"
android:text="Call to order a pack!"/>
</LinearLayout>
-------------------------------------------------------------------------
--------------------------------------------- DialActivity.java --------------------------------------------
package com.app.yourappname;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class DialActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dial_activity);
}
public void dialCall(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:123456789"));
startActivity(intent);
}
}
-------------------------------------------------------------
------------------------------------- Declare Acvitivy name in Manifest file -------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.app.yourappname">
<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=".DialActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
-------------------------------------------------------------
No comments:
Post a Comment