Make automatic calling again and again in android studio
Hello guys ! in this artical i am going to teach you step by step how can we make an android app that will call again and again by itself . now you can see video in which i explain in very easy language.
video link is below the code.
AndroidManifest.xml :-
<uses-permission android:name="android.permission.CALL_PHONE"/>
activity_main.xml :-
<?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/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:inputType="phone" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Call Again and angain"
android:layout_marginTop="10dp"
android:onClick="repeat"
/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop the call"
android:onClick="stoprepeat"
android:layout_marginTop="10dp"/>
</LinearLayout>Main activity.java :-package com.example.callrepeat;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText etnumber;
Handler mhandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etnumber = findViewById(R.id.et);
}
public void repeat(View view) {
mhandler.postDelayed(mtoastrunnable, 5000);
}
public void stoprepeat(View view) {
mhandler.removeCallbacks(mtoastrunnable);
Toast.makeText(this, "call has stopped", Toast.LENGTH_SHORT).show();
}
private Runnable mtoastrunnable = new Runnable() {
@Override
public void run() {
String phone = etnumber.getText().toString();
if (phone.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter mobile number", Toast.LENGTH_SHORT).show();
} else {
String s = "tel:" + phone;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(s));
startActivity(intent);
Toast.makeText(MainActivity.this, "Call attack is going", Toast.LENGTH_SHORT).show();
mhandler.postDelayed(mtoastrunnable, 5000);
}
}
};
}Now this was the our source code.Video link :- https://youtu.be/KpVXK95ziP4
0 Comments