How to Open Phone call, Email, WhatsApp, SMS, Facebook And YouTube in Android Studio With Lottie Animation - RSM Developer

  

Intent With Social Media 

Step 1Creating a new project

  • Open a new project.
  • We will be working on Empty Activity with language as Java. Leave all other options unchanged.
  • You can change the name of the project at your convenience.
  • There will be two default files named activity_main.xml and MainActivity.java.
Step 2: Open AndroidManifest And Permission Internet and Phone Call
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.CALL_PHONE" />

Step 3: Navigate to Build scripts > build.gradle(module) file and add the following dependency to it and Syne Now

//lotti=====================================================
implementation 'com.airbnb.android:lottie:5.2.0'


Step 4: Open res -> layout ->activity_main.xml (or) main.xml and add following code:

In this step we open an XML file and add the code :-

<?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"
android:background="@color/white"
tools:context=".MainActivity">

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
app:cardElevation="8dp"
app:cardCornerRadius="8dp"
app:cardBackgroundColor="@color/teal_700"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
>

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:lottie_url="https://assets6.lottiefiles.com/packages/lf20_ksklhijl.json"
app:lottie_autoPlay="true"
app:lottie_loop="true"
android:layout_weight="1"/>

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/wa"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:lottie_url="https://assets10.lottiefiles.com/private_files/lf30_qnpfavmd.json"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/sms"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:lottie_url="https://assets5.lottiefiles.com/packages/lf20_EYBNGy7MXe.json"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>

</LinearLayout>

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
app:cardElevation="8dp"
app:cardCornerRadius="8dp"
app:cardBackgroundColor="@color/teal_700"
>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
>
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/call"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:lottie_url="https://assets1.lottiefiles.com/packages/lf20_55bbjdzw.json"
app:lottie_autoPlay="true"
android:layout_weight="1"
android:layout_margin="2dp"
app:lottie_loop="true"/>

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/fb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:lottie_url="https://assets7.lottiefiles.com/private_files/lf30_hazkrlss.json"
app:lottie_autoPlay="true"
android:layout_weight="1"
android:layout_margin="2dp"
app:lottie_loop="true"/>

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/yt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
app:lottie_autoPlay="true"
app:lottie_loop="true"
android:layout_margin="2dp"
app:lottie_url="https://assets9.lottiefiles.com/packages/lf20_qe6rfoqh.json" />
</LinearLayout>
</androidx.cardview.widget.CardView>

</LinearLayout>

Step 5: Open Java -> package – > MainActivity.Java and add following code:

In this step we open an Java file and add the code :-

package com.rsmdeveloper.intentwithsm;


import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.airbnb.lottie.LottieAnimationView;

public class MainActivity extends AppCompatActivity {
//============================================================
LottieAnimationView call,sms,wa,email,fb,yt;
//============================================================

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

//call=======================================================================
call = findViewById(R.id.call);
call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String phone = "your phone number";
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null));
startActivity(intent);
}
});

//email===================================================================================================
email = findViewById(R.id.email);
email.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent mailIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "subject text"+ "&body=" + "body text " + "&to=" + "your email address");
mailIntent.setData(data);
startActivity(Intent.createChooser(mailIntent, "Send mail..."));
}
});

//watsapp=======================================================================
wa = findViewById(R.id.wa);
wa.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
String mobile = "your whatsapp number";
String msg = "Its Working";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send?phone=" + mobile + "&text=" + msg)));
}catch (Exception e){
//whatsapp app not install
}
}
});
//sms=======================================================================
sms = findViewById(R.id.sms);
sms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri sms_uri = Uri.parse("smsto:your sms number");
Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri);
sms_intent.putExtra("sms_body", "Write your opinion.");
startActivity(sms_intent);
}
});
//facebook========================================================================
fb = findViewById(R.id.fb);
fb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = "https://www.facebook.com/page name/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

}
});
//youtube========================================================================
yt = findViewById(R.id.yt);
yt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = "https://www.youtube.com/youtube name/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
//========================================================================
}
}

Output:
Now run the App and you will see main topics and sub-topics listed.....
Watch Video

Intent With Phone call in android studio, Intent With SMS in android studio, Intent With Email  in android studio, Intent With WhatsApp in android studio, Intent With Facebook
in android studio, Intent With YouTube in android studio, Intent With Social Media in android studio,

Post a Comment

Previous Post Next Post

যোগাযোগ ফর্ম