fahad005

love

Dec 29th, 2021
1,254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.49 KB | None | 0 0
  1. package com.example.phonecall;
  2.  
  3. import android.Manifest;
  4. import android.content.Intent;
  5. import android.content.pm.PackageManager;
  6. import android.net.Uri;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.ImageView;
  12. import android.widget.Toast;
  13.  
  14. import androidx.annotation.NonNull;
  15. import androidx.appcompat.app.AppCompatActivity;
  16. import androidx.core.app.ActivityCompat;
  17. import androidx.core.content.ContextCompat;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20.     private static final int REQUEST_CALL = 1;
  21.     private EditText mEditTextNumber;
  22.  
  23.     @Override
  24.     protected void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.activity_main);
  27.  
  28.         //mEditTextNumber = findViewById(R.id.edit_text_number);
  29.         ImageView imageCall = findViewById(R.id.image_call);
  30.         Button btn = findViewById(R.id.continuous);
  31.  
  32.         imageCall.setOnClickListener(new View.OnClickListener() {
  33.             @Override
  34.             public void onClick(View v) {
  35.                 makePhoneCall();
  36.             }
  37.         });
  38.         btn.setOnClickListener(new View.OnClickListener() {
  39.             @Override
  40.             public void onClick(View v) {
  41.                 for (int i = 0; i < 10; i++) makePhoneCall();
  42.             }
  43.         });
  44.     }
  45.  
  46.     private void makePhoneCall() {
  47.         //String number = mEditTextNumber.getText().toString();
  48.         String number = "01893713798";
  49.         if (number.trim().length() > 0) {
  50.  
  51.             if (ContextCompat.checkSelfPermission(MainActivity.this,
  52.                     Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
  53.                 ActivityCompat.requestPermissions(MainActivity.this,
  54.                         new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL);
  55.             } else {
  56.                 String dial = "tel:" + number;
  57.                 startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
  58.             }
  59.  
  60.         } else {
  61.             Toast.makeText(MainActivity.this, "Enter Phone Number", Toast.LENGTH_SHORT).show();
  62.         }
  63.     }
  64.  
  65.     @Override
  66.     public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  67.         super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  68.         if (requestCode == REQUEST_CALL) {
  69.             if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  70.                 makePhoneCall();
  71.             } else {
  72.                 Toast.makeText(this, "Permission DENIED", Toast.LENGTH_SHORT).show();
  73.             }
  74.         }
  75.     }
  76.  
  77. }
  78.  
  79.  
  80. <?xml version="1.0" encoding="utf-8"?>
  81. <LinearLayout xmlns:tools="http://schemas.android.com/tools"
  82.     xmlns:android="http://schemas.android.com/apk/res/android"
  83.     android:layout_width="match_parent"
  84.     android:layout_height="match_parent"
  85.     android:orientation="vertical"
  86.     tools:context=".MainActivity">
  87.  
  88. <!--    <EditText-->
  89. <!--        android:id="@+id/edit_text_number"-->
  90. <!--        android:layout_width="match_parent"-->
  91. <!--        android:layout_height="wrap_content"-->
  92. <!--        android:layout_alignParentStart="true"-->
  93. <!--        android:layout_alignParentTop="true"-->
  94. <!--        android:layout_marginTop="147dp"-->
  95. <!--        android:inputType="phone" />-->
  96.  
  97.     <ImageView
  98.         android:id="@+id/nothing"
  99.         android:layout_width="match_parent"
  100.         android:layout_height="277dp"
  101.         android:layout_marginTop="25dp"
  102.         android:src="@drawable/abc" />
  103.  
  104.     <TextView
  105.         android:layout_width="wrap_content"
  106.         android:layout_height="wrap_content"
  107.         android:text="Call Anonna"
  108.         android:textSize="40dp"
  109.         android:layout_gravity="center"
  110.         android:layout_marginTop="10dp"
  111.         android:textColor="#ff0000"/>
  112.  
  113.     <ImageView
  114.         android:id="@+id/image_call"
  115.         android:layout_width="80dp"
  116.         android:layout_height="80dp"
  117.         android:layout_marginTop="20dp"
  118.         android:layout_gravity="center"
  119.         android:src="@drawable/ic_phone" />
  120.  
  121.     <Button
  122.         android:id="@+id/continuous"
  123.         android:layout_width="wrap_content"
  124.         android:layout_height="wrap_content"
  125.         android:padding="5dp"
  126.         android:text="Continuous Call"
  127.         android:layout_marginTop="20dp"
  128.         android:layout_marginLeft="30dp"
  129.         />
  130.  
  131. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment