質問編集履歴
1
見えやすくしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,98 +10,108 @@
|
|
10
10
|
|
11
11
|
|
12
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
13
|
+
■エラーのデバック内容
|
14
|
+
|
15
|
+
```ここに言語を入力
|
16
|
+
|
17
|
+
**E/AndroidRuntime: FATAL EXCEPTION: main
|
18
|
+
|
19
|
+
Process: com.example.sample, PID: 20758
|
20
|
+
|
21
|
+
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1111, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/258r132-2606083C030D6026260816030D602668/115 flg=0x1 }} to activity {com.example.sample/com.example.sample.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/data/phones from pid=20758, uid=10344 requires android.permission.READ_CONTACTS, or grantUriPermission()
|
22
|
+
|
23
|
+
at android.app.ActivityThread.deliverResults(ActivityThread.java:4382)
|
24
|
+
|
25
|
+
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4424)
|
26
|
+
|
27
|
+
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
|
28
|
+
|
29
|
+
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
|
30
|
+
|
31
|
+
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
|
32
|
+
|
33
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
|
34
|
+
|
35
|
+
at android.os.Handler.dispatchMessage(Handler.java:106)
|
36
|
+
|
37
|
+
at android.os.Looper.loop(Looper.java:280)
|
38
|
+
|
39
|
+
at android.app.ActivityThread.main(ActivityThread.java:6706)
|
40
|
+
|
41
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
42
|
+
|
43
|
+
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
|
44
|
+
|
45
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
|
46
|
+
|
47
|
+
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/data/phones from pid=20758, uid=10344 requires android.permission.READ_CONTACTS, or grantUriPermission()
|
48
|
+
|
49
|
+
at android.os.Parcel.createException(Parcel.java:1969)
|
50
|
+
|
51
|
+
at android.os.Parcel.readException(Parcel.java:1935)
|
52
|
+
|
53
|
+
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
|
54
|
+
|
55
|
+
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
|
56
|
+
|
57
|
+
at android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
|
58
|
+
|
59
|
+
at android.content.ContentResolver.query(ContentResolver.java:804)
|
60
|
+
|
61
|
+
at android.content.ContentResolver.query(ContentResolver.java:753)
|
62
|
+
|
63
|
+
at android.content.ContentResolver.query(ContentResolver.java:711)
|
64
|
+
|
65
|
+
at com.example.sample.MainActivity._getPhoneNumbers(MainActivity.java:122)
|
66
|
+
|
67
|
+
at com.example.sample.MainActivity.onActivityResult(MainActivity.java:70)
|
68
|
+
|
69
|
+
at android.app.Activity.dispatchActivityResult(Activity.java:7454)
|
70
|
+
|
71
|
+
at android.app.ActivityThread.deliverResults(ActivityThread.java:4375)
|
72
|
+
|
73
|
+
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4424)
|
74
|
+
|
75
|
+
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
|
76
|
+
|
77
|
+
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
|
78
|
+
|
79
|
+
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
|
80
|
+
|
81
|
+
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
|
82
|
+
|
83
|
+
at android.os.Handler.dispatchMessage(Handler.java:106)
|
84
|
+
|
85
|
+
at android.os.Looper.loop(Looper.java:280)
|
86
|
+
|
87
|
+
at android.app.ActivityThread.main(ActivityThread.java:6706)
|
88
|
+
|
89
|
+
at java.lang.reflect.Method.invoke(Native Method)
|
90
|
+
|
91
|
+
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
|
92
|
+
|
93
|
+
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
|
90
94
|
|
91
95
|
I/Process: Sending signal. PID: 20758 SIG: 9
|
92
96
|
|
93
97
|
|
94
98
|
|
95
|
-
|
99
|
+
```
|
100
|
+
|
96
|
-
|
101
|
+
```****
|
102
|
+
|
97
|
-
|
103
|
+
■作成したプログラム
|
104
|
+
|
98
|
-
|
105
|
+
```ここに言語を入力
|
106
|
+
|
99
|
-
|
107
|
+
```ここに言語を入力
|
100
108
|
|
101
109
|
package com.example.sample;
|
102
110
|
|
103
111
|
|
104
112
|
|
113
|
+
import android.Manifest;
|
114
|
+
|
105
115
|
import android.app.Activity;
|
106
116
|
|
107
117
|
import android.app.AlertDialog;
|
@@ -130,6 +140,10 @@
|
|
130
140
|
|
131
141
|
|
132
142
|
|
143
|
+
import androidx.core.app.ActivityCompat;
|
144
|
+
|
145
|
+
|
146
|
+
|
133
147
|
import com.mkyong.android.R;
|
134
148
|
|
135
149
|
|
@@ -150,6 +164,8 @@
|
|
150
164
|
|
151
165
|
private static final int PICK_CONTACT = 1111;
|
152
166
|
|
167
|
+
private static final int REQUEST_CODE = 1000;
|
168
|
+
|
153
169
|
|
154
170
|
|
155
171
|
private AlertDialog.Builder _alertDialogBuilder;
|
@@ -182,7 +198,7 @@
|
|
182
198
|
|
183
199
|
this._alertDialogBuilder = new AlertDialog.Builder(this);
|
184
200
|
|
185
|
-
this._phoneNumberTextView = (TextView) this.findViewById(R.id.text);
|
201
|
+
this._phoneNumberTextView = (TextView) this.findViewById(R.id.textView);
|
186
202
|
|
187
203
|
|
188
204
|
|
@@ -278,7 +294,11 @@
|
|
278
294
|
|
279
295
|
String selectedPhoneNumber = this._phoneNumbers[which];
|
280
296
|
|
281
|
-
|
297
|
+
Uri uri = Uri.parse("tel:" + selectedPhoneNumber);
|
298
|
+
|
299
|
+
Intent i = new Intent(Intent.ACTION_CALL,uri);
|
300
|
+
|
301
|
+
startActivity(i);
|
282
302
|
|
283
303
|
}
|
284
304
|
|
@@ -324,74 +344,82 @@
|
|
324
344
|
|
325
345
|
|
326
346
|
|
347
|
+
//
|
348
|
+
|
349
|
+
// コンタクトリストから表示名で検索して、その名前に紐付いている電話番号を取得する
|
350
|
+
|
351
|
+
//
|
352
|
+
|
353
|
+
// @param displayName
|
354
|
+
|
355
|
+
// @return
|
356
|
+
|
357
|
+
//
|
358
|
+
|
359
|
+
private String[] _getPhoneNumbers(String displayName) {
|
360
|
+
|
361
|
+
ContentResolver contentResolver = this.getContentResolver();
|
362
|
+
|
363
|
+
Cursor cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
|
364
|
+
|
365
|
+
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + "=?",
|
366
|
+
|
367
|
+
new String[] { displayName }, null);
|
368
|
+
|
369
|
+
cursor.moveToFirst();
|
370
|
+
|
371
|
+
String[] names = new String[cursor.getCount()];
|
372
|
+
|
373
|
+
do {
|
374
|
+
|
375
|
+
int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
376
|
+
|
377
|
+
String number = cursor.getString(index);
|
378
|
+
|
379
|
+
names[cursor.getPosition()] = number;
|
380
|
+
|
381
|
+
} while (cursor.moveToNext());
|
382
|
+
|
383
|
+
cursor.close();
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
return names;
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
327
393
|
/**
|
328
394
|
|
329
|
-
*
|
395
|
+
* 電話番号選択のダイアログを出す
|
330
396
|
|
331
397
|
*
|
332
398
|
|
333
|
-
* @param
|
399
|
+
* @param title
|
334
|
-
|
400
|
+
|
335
|
-
* @re
|
401
|
+
* @param items
|
336
402
|
|
337
403
|
*/
|
338
404
|
|
339
|
-
private String[] _getPhoneNumbers(String displayName) {
|
340
|
-
|
341
|
-
ContentResolver contentResolver = this.getContentResolver();
|
342
|
-
|
343
|
-
Cursor cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
|
344
|
-
|
345
|
-
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + "=?",
|
346
|
-
|
347
|
-
new String[] { displayName }, null);
|
348
|
-
|
349
|
-
cursor.moveToFirst();
|
350
|
-
|
351
|
-
String[] names = new String[cursor.getCount()];
|
352
|
-
|
353
|
-
do {
|
354
|
-
|
355
|
-
int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
356
|
-
|
357
|
-
String number = cursor.getString(index);
|
358
|
-
|
359
|
-
names[cursor.getPosition()] = number;
|
360
|
-
|
361
|
-
} while (cursor.moveToNext());
|
362
|
-
|
363
|
-
cursor.close();
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
return names;
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
/**
|
374
|
-
|
375
|
-
* 電話番号選択のダイアログを出す
|
376
|
-
|
377
|
-
*
|
378
|
-
|
379
|
-
* @param title
|
380
|
-
|
381
|
-
* @param items
|
382
|
-
|
383
|
-
*/
|
384
|
-
|
385
405
|
private void _createNumberSelectAlertDialog(String title, String[] items) {
|
386
406
|
|
387
407
|
this._alertDialogBuilder.setTitle(title);
|
388
408
|
|
389
409
|
this._alertDialogBuilder.setItems(items, this);
|
390
410
|
|
391
|
-
AlertDialog al
|
411
|
+
AlertDialog dialog = this._alertDialogBuilder.create();
|
392
|
-
|
412
|
+
|
393
|
-
al
|
413
|
+
dialog.show();
|
394
|
-
|
414
|
+
|
395
|
-
}
|
415
|
+
}
|
416
|
+
|
417
|
+
|
396
418
|
|
397
419
|
}
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
```
|
424
|
+
|
425
|
+
```
|