Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.tp11;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.app.ActivityCompat;
- import android.Manifest;
- import android.content.Intent;
- import android.content.pm.PackageManager;
- import android.net.Uri;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- private int CALL_Perm = 0;
- private String phonenum;
- private String url;
- EditText edt;
- EditText stw;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, CALL_Perm);
- public void siteweb(View view) {
- stw = findViewById(R.id.website);
- url = stw.getEditableText().toString();
- if (url==null){Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://inpt.ac.ma/"));
- startActivity(browserIntent);}
- else{Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- startActivity(browserIntent);}
- }
- public void appel(View view) {
- ActivityCompat.requestPermissions(this, new String[]
- {Manifest.permission.CALL_PHONE}, CALL_Perm);
- edt=findViewById(R.id.phonec);
- phonenum=edt.getEditableText().toString();
- Intent phoneIntent = new Intent(Intent.ACTION_DIAL);
- phoneIntent.setData(Uri.parse("tel:"+Uri.encode(phonenum)));
- }
- public void launchact(View view) {
- Intent persoact = new Intent(this, ActivitePerso.class);
- startActivity(persoact);
- }
- @Override
- public void onRequestPermissionsResult(int requestCode,
- String[] permissions, int[] grantResults) {
- super.onRequestPermissionsResult(requestCode,
- permissions, grantResults);
- //check the permission type using the requestCode
- if (requestCode == CALL_Perm) {
- //the array is empty if not granted
- if (grantResults.length > 0 &&
- grantResults[0] == PackageManager.PERMISSION_GRANTED)
- Toast.makeText(this, "GRANTED CALL",
- Toast.LENGTH_SHORT).show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement