44import android .content .Context ;
55import android .content .Intent ;
66import android .net .Uri ;
7- import android .os .Build ;
8- import android .provider .Telephony ;
97
108import androidx .annotation .NonNull ;
119
12- import android .text .TextUtils ;
13-
14- import static android .content .Intent .ACTION_DIAL ;
15-
1610public class PhoneIntents
1711{
18- public static final int REQUEST_SELECT_PHONE_NUMBER = 6 ;
1912 private Context context ;
2013 private Intent intent ;
2114
@@ -29,150 +22,21 @@ public static PhoneIntents from(@NonNull Context context)
2922 return new PhoneIntents (context );
3023 }
3124
32- public PhoneIntents newEmptySmsIntent ()
33- {
34- return newSmsIntent (null , (String []) null );
35- }
36-
37- public PhoneIntents newEmptySmsIntent (String phoneNumber )
38- {
39- return newSmsIntent (null , new String []{phoneNumber });
40- }
41-
42- public PhoneIntents newEmptySmsIntent (String [] phoneNumbers )
43- {
44- return newSmsIntent (null , phoneNumbers );
45- }
46-
47- public PhoneIntents newSmsIntent (String body )
25+ public PhoneIntents showDialNumber ()
4826 {
49- return newSmsIntent (body , (String []) null );
50- }
51-
52- public PhoneIntents newSmsIntent (String body , String phoneNumber )
53- {
54- return newSmsIntent (body , new String []{phoneNumber });
55- }
56-
57- public PhoneIntents newSmsIntent (String body , String [] phoneNumbers )
58- {
59- Uri smsUri ;
60- if (phoneNumbers == null || phoneNumbers .length == 0 )
61- {
62- smsUri = Uri .parse ("smsto:" );
63- } else
64- {
65- smsUri = Uri .parse ("smsto:" + Uri .encode (TextUtils .join ("," , phoneNumbers )));
66- }
67-
68-
69- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .KITKAT )
70- {
71- intent = new Intent (Intent .ACTION_SENDTO , smsUri );
72- intent .setPackage (Telephony .Sms .getDefaultSmsPackage (context ));
73- } else
74- {
75- intent = new Intent (Intent .ACTION_VIEW , smsUri );
76- }
77-
78- if (body != null )
79- {
80- intent .putExtra ("sms_body" , body );
81- }
82-
27+ intent = new Intent (Intent .ACTION_DIAL , Uri .parse ("tel:" ));
8328 return this ;
8429 }
8530
86- public PhoneIntents newDialNumberIntent (String phoneNumber )
31+ public PhoneIntents showDialNumber (String phoneNumber )
8732 {
88-
89- if (phoneNumber == null || phoneNumber .trim ().length () <= 0 )
90- {
91- intent = new Intent (Intent .ACTION_DIAL , Uri .parse ("tel:" ));
92- } else
93- {
94- intent = new Intent (Intent .ACTION_DIAL , Uri .parse ("tel:" + phoneNumber .replace (" " , "" )));
95- }
33+ intent = new Intent (Intent .ACTION_DIAL , Uri .parse ("tel:" + phoneNumber .replace (" " , "" )));
9634 return this ;
9735 }
9836
99- public PhoneIntents newCallNumberIntent (String phoneNumber )
37+ public PhoneIntents callNumber (String phoneNumber )
10038 {
101-
102- if (phoneNumber == null || phoneNumber .trim ().length () <= 0 )
103- {
104- intent = new Intent (Intent .ACTION_CALL , Uri .parse ("tel:" ));
105- } else
106- {
107- intent = new Intent (Intent .ACTION_CALL , Uri .parse ("tel:" + phoneNumber .replace (" " , "" )));
108- }
109-
110- return this ;
111- }
112-
113- public PhoneIntents newPickContactIntent ()
114- {
115- return newPickContactIntent (null );
116- }
117-
118- public PhoneIntents openEmptySmsIntent ()
119- {
120- return newSmsIntent (null , (String []) null );
121- }
122-
123- public PhoneIntents openSmsNumberIntent (String phoneNumber )
124- {
125- if (phoneNumber != null )
126- return newSmsIntent (null , new String []{phoneNumber });
127- return null ;
128- }
129-
130- public PhoneIntents openSmsNumbersIntent (String [] phoneNumbers )
131- {
132- return newSmsIntent (null , phoneNumbers );
133- }
134-
135-
136- public PhoneIntents openSmsBodyIntent (String body )
137- {
138- return newSmsIntent (body , (String []) null );
139- }
140-
141- public PhoneIntents openSmsNumberBodyIntent (String body , String phoneNumber )
142- {
143- return newSmsIntent (body , new String []{phoneNumber });
144- }
145-
146- public PhoneIntents openSmsNumbersBodyIntent (String body , String [] phoneNumbers )
147- {
148- return newSmsIntent (body , phoneNumbers );
149- }
150-
151- @ SuppressWarnings ("deprecation" )
152- public PhoneIntents newPickContactIntent (String scope )
153- {
154- intent = new Intent (Intent .ACTION_PICK , Uri .parse ("content://com.android.contacts/contacts" ));
155-
156- if (!TextUtils .isEmpty (scope ))
157- {
158- intent .setType (scope );
159- }
160- return this ;
161- }
162-
163- public PhoneIntents callPhone (String phoneNumber )
164- {
165- intent = new Intent ();
166- intent .setAction (Intent .ACTION_CALL );
167- intent .setData (Uri .parse ("tel:" + phoneNumber ));
168- return this ;
169- }
170-
171- public PhoneIntents dialPhone (String phoneNumber )
172- {
173- intent = new Intent ();
174- intent .setAction (Intent .ACTION_DIAL );
175- intent .setData (Uri .parse ("tel:" + phoneNumber ));
39+ intent = new Intent (Intent .ACTION_CALL , Uri .parse ("tel:" + phoneNumber .replace (" " , "" )));
17640 return this ;
17741 }
17842
@@ -194,33 +58,4 @@ public void show()
19458 {
19559 startActivity (build ());
19660 }
197-
198- public PhoneIntents openDialNumberIntent (String phoneNumber )
199- {
200- if (phoneNumber == null || phoneNumber .trim ().length () <= 0 )
201- {//b te
202- intent = new Intent (ACTION_DIAL , Uri .parse ("tel:" ));
203- } else
204- {
205- intent = new Intent (ACTION_DIAL , Uri .parse ("tel:" + phoneNumber .replace (" " , "" )));
206- }
207- return this ;
208- }
209-
210- // TODO: 8/30/2017 Needed To see The main Page Remember.
211- public PhoneIntents InitiatePhoneDial (String phoneNumber )
212- {
213- intent = new Intent (Intent .ACTION_DIAL );
214- intent .setData (Uri .parse ("tel:" + phoneNumber ));
215- return this ;
216- }
217-
218- // TODO: 8/30/2017 Need Permission : <uses-permission android:name="android.permission.CALL_PHONE" />
219- // TODO: 8/30/2017 Needed To see The main Page Remember.
220- public PhoneIntents InitiatePhoneCall (String phoneNumber )
221- {
222- intent = new Intent (Intent .ACTION_CALL );
223- intent .setData (Uri .parse ("tel:" + phoneNumber ));
224- return this ;
225- }
22661}
0 commit comments