-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhoneCall.java
69 lines (62 loc) · 2.62 KB
/
PhoneCall.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.mtuity.contacts;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
/**
* Created by avinash
*/
public class PhoneCall {
private static int REQUEST_TYPE = 0;
private final Context context;
public PhoneCall(Context contxt) {
if (contxt != null) {
context = contxt;
} else {
throw new NullPointerException("Context should not be null.");
}
}
public static int getRequestType() {
return REQUEST_TYPE;
}
/**
* @param phoneNumber for which the call is placed
*/
public void makePhoneCall(String phoneNumber) {
REQUEST_TYPE = Constants.PhoneCall.MAKE_CALL;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel: " + phoneNumber));
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// Consider calling
// -- ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// -- public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
context.startActivity(callIntent);
}
/**
* @param phoneNumber for which the call is placed
*/
public void showPhoneNumberOnDialPad(String phoneNumber) {
REQUEST_TYPE = Constants.PhoneCall.DIAL_PAD_CALL;
Intent dialIntent = new Intent(Intent.ACTION_DIAL);
dialIntent.setData(Uri.parse("tel: " + phoneNumber));
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// Consider calling
// -- ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// -- public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
context.startActivity(dialIntent);
}
}