Advertisement
Guest User

xxxx

a guest
Mar 31st, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. package com.example.tp11;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.core.app.ActivityCompat;
  5.  
  6. import android.Manifest;
  7. import android.content.Intent;
  8. import android.content.pm.PackageManager;
  9. import android.net.Uri;
  10. import android.os.Bundle;
  11. import android.view.View;
  12. import android.widget.EditText;
  13. import android.widget.Toast;
  14.  
  15. public class MainActivity extends AppCompatActivity {
  16. private int CALL_Perm = 0;
  17. private String phonenum;
  18. private String url;
  19. EditText edt;
  20. EditText stw;
  21.  
  22. @Override
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.activity_main);
  26. }
  27. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, CALL_Perm);
  28.  
  29. public void siteweb(View view) {
  30. stw = findViewById(R.id.website);
  31. url = stw.getEditableText().toString();
  32. if (url==null){Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://inpt.ac.ma/"));
  33. startActivity(browserIntent);}
  34. else{Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  35. startActivity(browserIntent);}
  36.  
  37.  
  38. }
  39.  
  40. public void appel(View view) {
  41. ActivityCompat.requestPermissions(this, new String[]
  42. {Manifest.permission.CALL_PHONE}, CALL_Perm);
  43. edt=findViewById(R.id.phonec);
  44. phonenum=edt.getEditableText().toString();
  45. Intent phoneIntent = new Intent(Intent.ACTION_DIAL);
  46. phoneIntent.setData(Uri.parse("tel:"+Uri.encode(phonenum)));
  47. }
  48.  
  49. public void launchact(View view) {
  50. Intent persoact = new Intent(this, ActivitePerso.class);
  51. startActivity(persoact);
  52. }
  53.  
  54. @Override
  55. public void onRequestPermissionsResult(int requestCode,
  56. String[] permissions, int[] grantResults) {
  57. super.onRequestPermissionsResult(requestCode,
  58. permissions, grantResults);
  59. //check the permission type using the requestCode
  60. if (requestCode == CALL_Perm) {
  61. //the array is empty if not granted
  62. if (grantResults.length > 0 &&
  63. grantResults[0] == PackageManager.PERMISSION_GRANTED)
  64. Toast.makeText(this, "GRANTED CALL",
  65. Toast.LENGTH_SHORT).show();
  66. }
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement