質問編集履歴
1
MainActivityのコードを追加しました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Androidアプリに表示される「エラーコード:3」の解決
|
1
|
+
AndroidStudioで作成したアプリに表示される「エラーコード:3」の解決
|
test
CHANGED
@@ -10,8 +10,548 @@
|
|
10
10
|
|
11
11
|
何か解決方法、原因を教えていただけないかと思います。
|
12
12
|
|
13
|
+
```MainActivity
|
14
|
+
|
15
|
+
public class MainActivity extends AppCompatActivity
|
16
|
+
|
17
|
+
implements View.OnClickListener, RecognitionListener{
|
18
|
+
|
19
|
+
private static final String TAG = MainActivity.class.getSimpleName();
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
//省略
|
24
|
+
|
25
|
+
private boolean _bConnected;
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
private Handler _handler;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
@Override
|
34
|
+
|
35
|
+
protected void onCreate(Bundle savedInstanceState) {
|
36
|
+
|
37
|
+
Window wnd = getWindow();
|
38
|
+
|
39
|
+
wnd.addFlags(Window.FEATURE_NO_TITLE);
|
40
|
+
|
41
|
+
super.onCreate(savedInstanceState);
|
42
|
+
|
43
|
+
setContentView(R.layout.activity_main);
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
});
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
_handler = new Handler(Looper.getMainLooper());
|
52
|
+
|
53
|
+
final Activity activity = this;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
_handler = new Handler(Looper.getMainLooper());
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
PeerOption option = new PeerOption();
|
64
|
+
|
65
|
+
option.key = API_KEY;
|
66
|
+
|
67
|
+
option.domain = DOMAIN;
|
68
|
+
|
69
|
+
option.debug = Peer.DebugLevelEnum.ALL_LOGS;
|
70
|
+
|
71
|
+
_peer = new Peer(this, option);
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
_peer.on(Peer.PeerEventEnum.OPEN, new OnCallback() {
|
78
|
+
|
79
|
+
@Override
|
80
|
+
|
81
|
+
public void onCallback(Object object) {
|
82
|
+
|
83
|
+
_strOwnId = (String) object;
|
84
|
+
|
85
|
+
TextView tvOwnId = (TextView) findViewById(R.id.tvOwnId);
|
86
|
+
|
87
|
+
tvOwnId.setText(_strOwnId);
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
if (ContextCompat.checkSelfPermission(activity,
|
92
|
+
|
93
|
+
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(activity,
|
94
|
+
|
95
|
+
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
96
|
+
|
97
|
+
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, 0);
|
98
|
+
|
99
|
+
} else {
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
startLocalStream();
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
});
|
112
|
+
|
113
|
+
_peer.on(Peer.PeerEventEnum.CALL, new OnCallback() {
|
114
|
+
|
115
|
+
@Override
|
116
|
+
|
117
|
+
public void onCallback(Object object) {
|
118
|
+
|
119
|
+
//省略
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
closeRemoteStream();
|
124
|
+
|
125
|
+
_mediaConnection.close(true);
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
v.setEnabled(true);
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
});
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
Button switchCameraAction = (Button) findViewById(R.id.switchCameraAction);
|
144
|
+
|
145
|
+
switchCameraAction.setOnClickListener(new View.OnClickListener() {
|
146
|
+
|
147
|
+
@Override
|
148
|
+
|
149
|
+
public void onClick(View v) {
|
150
|
+
|
151
|
+
if (null != _localStream) {
|
152
|
+
|
153
|
+
Boolean result = _localStream.switchCamera();
|
154
|
+
|
155
|
+
if (true == result) {
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
} else {
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
});
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
mButton = (Button) findViewById(R.id.speech_button);
|
176
|
+
|
177
|
+
mText = (TextView) findViewById(R.id.output_text);
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
mButton.setOnClickListener(this);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
mRecorder = null;
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
mAlert = new AlertDialog.Builder(this);
|
190
|
+
|
191
|
+
mAlert.setTitle("エラー");
|
192
|
+
|
193
|
+
mAlert.setPositiveButton("OK", null);
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
checkRecordable();
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
public Boolean checkRecordable() {
|
206
|
+
|
207
|
+
if (!SpeechRecognizer.isRecognitionAvailable(getApplicationContext())) {
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
mText.setText("音声認識が使用できません");
|
212
|
+
|
213
|
+
return false;
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
if (Build.VERSION.SDK_INT >= 23) {
|
218
|
+
|
219
|
+
if (ActivityCompat.checkSelfPermission(this,
|
220
|
+
|
221
|
+
Manifest.permission.RECORD_AUDIO)
|
222
|
+
|
223
|
+
!= PackageManager.PERMISSION_GRANTED) {
|
224
|
+
|
225
|
+
mText.setText("マイクの使用を許可してください");
|
226
|
+
|
227
|
+
ActivityCompat.requestPermissions(this,
|
228
|
+
|
229
|
+
new String[]{
|
230
|
+
|
231
|
+
Manifest.permission.RECORD_AUDIO},
|
232
|
+
|
233
|
+
PERMISSION_RECORD_AUDIO);
|
234
|
+
|
235
|
+
return false;
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
return true;
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
@Override
|
248
|
+
|
249
|
+
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
250
|
+
|
251
|
+
switch (requestCode) {
|
252
|
+
|
253
|
+
//省略
|
254
|
+
|
255
|
+
break;
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
@Override
|
264
|
+
|
265
|
+
protected void onStart() {
|
266
|
+
|
267
|
+
super.onStart();
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
View decorView = getWindow().getDecorView();
|
272
|
+
|
273
|
+
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
Window wnd = getWindow();
|
278
|
+
|
279
|
+
wnd.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
280
|
+
|
281
|
+
wnd.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
@Override
|
288
|
+
|
289
|
+
protected void onResume() {
|
290
|
+
|
291
|
+
super.onResume();
|
292
|
+
|
293
|
+
/////省略
|
294
|
+
|
295
|
+
super.onDestroy();
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
void startLocalStream() {
|
302
|
+
|
303
|
+
Navigator.initialize(_peer);
|
304
|
+
|
305
|
+
MediaConstraints constraints = new MediaConstraints();
|
306
|
+
|
307
|
+
_localStream = Navigator.getUserMedia(constraints);
|
308
|
+
|
309
|
+
Canvas canvas = (Canvas) findViewById(R.id.svLocalView);
|
310
|
+
|
311
|
+
_localStream.addVideoRenderer(canvas, 0);
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
void setMediaCallbacks() {
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
_mediaConnection.on(MediaConnection.MediaEventEnum.STREAM, new OnCallback() {
|
322
|
+
|
323
|
+
@Override
|
324
|
+
|
325
|
+
public void onCallback(Object object) {
|
326
|
+
|
327
|
+
_remoteStream = (MediaStream) object;
|
328
|
+
|
329
|
+
Canvas canvas = (Canvas) findViewById(R.id.svRemoteView);
|
330
|
+
|
331
|
+
_remoteStream.addVideoRenderer(canvas, 0);
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
});
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
//省略
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
updateActionButtonTitle();
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
void showPeerIDs() {
|
350
|
+
|
351
|
+
if ((null == _peer) || (null == _strOwnId) || (0 == _strOwnId.length())) {
|
352
|
+
|
353
|
+
//省略
|
354
|
+
|
355
|
+
} else {
|
356
|
+
|
357
|
+
Toast.makeText(fContext, "PeerID list (other than your ID) is empty.", Toast.LENGTH_SHORT).show();
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
});
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
void updateActionButtonTitle() {
|
370
|
+
|
371
|
+
_handler.post(new Runnable() {
|
372
|
+
|
373
|
+
@Override
|
374
|
+
|
375
|
+
public void run() {
|
376
|
+
|
377
|
+
Button btnAction = (Button) findViewById(R.id.btnAction);
|
378
|
+
|
379
|
+
if (null != btnAction) {
|
380
|
+
|
381
|
+
if (false == _bConnected) {
|
382
|
+
|
383
|
+
btnAction.setText("Make Call");
|
384
|
+
|
385
|
+
} else {
|
386
|
+
|
387
|
+
btnAction.setText("Hang up");
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
}
|
394
|
+
|
395
|
+
});
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
public void stopRecording() {
|
400
|
+
|
401
|
+
//省略
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
mButton.setText(getString(R.string.stop_speech));
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
@Override
|
414
|
+
|
415
|
+
public void onClick(View v) {
|
416
|
+
|
417
|
+
if(v.getId() != R.id.speech_button){
|
418
|
+
|
419
|
+
return;
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
if(mRecorder != null){
|
424
|
+
|
425
|
+
stopRecording();
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
else{
|
430
|
+
|
431
|
+
startRecording();
|
432
|
+
|
433
|
+
}
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
@Override
|
440
|
+
|
441
|
+
public void onReadyForSpeech(Bundle params) {
|
442
|
+
|
443
|
+
Log.d("MainActivity","onReadyForSpeech");
|
444
|
+
|
445
|
+
mText.setText(getString(R.string.ready_speech));
|
446
|
+
|
447
|
+
}
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
@Override
|
452
|
+
|
453
|
+
public void onBeginningOfSpeech() {
|
454
|
+
|
455
|
+
Log.d("MainActivity","onBeginningOfSpeech");
|
456
|
+
|
457
|
+
mText.setText("");
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
@Override
|
464
|
+
|
465
|
+
public void onBufferReceived(byte[] buffer) {
|
466
|
+
|
467
|
+
Log.d("MainActivity","onBufferReceived");
|
468
|
+
|
469
|
+
}
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
@Override
|
474
|
+
|
475
|
+
public void onRmsChanged(float rmsdB) {
|
476
|
+
|
477
|
+
Log.d("MainActivity","onRmsChanged");
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
@Override
|
484
|
+
|
485
|
+
public void onEndOfSpeech() {
|
486
|
+
|
487
|
+
Log.d("MainActivity","onEndOfSpeech");
|
488
|
+
|
489
|
+
stopRecording();
|
490
|
+
|
491
|
+
}
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
@Override
|
496
|
+
|
497
|
+
public void onError(int error) {
|
498
|
+
|
499
|
+
Log.d("MainActivity","onError.error="+error);
|
500
|
+
|
501
|
+
mText.setText(getString(R.string.speech_error) + "\nエラーコード:" + error);
|
502
|
+
|
503
|
+
stopRecording();
|
504
|
+
|
505
|
+
}
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
@Override
|
510
|
+
|
511
|
+
public void onEvent(int eventType, Bundle params) {
|
512
|
+
|
513
|
+
Log.d("MainActivity","onEvent.eventType="+eventType);
|
514
|
+
|
515
|
+
}
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
@Override
|
520
|
+
|
521
|
+
public void onPartialResults(Bundle partialResults) {
|
522
|
+
|
523
|
+
Log.d("MainActivity","onPartialResults");
|
524
|
+
|
525
|
+
String str = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).get(0);
|
526
|
+
|
527
|
+
if(str.length() > 0) {
|
528
|
+
|
529
|
+
mText.setText(str);
|
530
|
+
|
531
|
+
}
|
532
|
+
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
@Override
|
538
|
+
|
539
|
+
public void onResults(Bundle results) {
|
540
|
+
|
541
|
+
Log.d("MainActivity","onResults");
|
542
|
+
|
543
|
+
}
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
}
|
548
|
+
|
549
|
+
```
|
550
|
+
|
13
551
|
下の二つのURLを組み合わせています。
|
14
552
|
|
553
|
+
省略部分はURLのものと同じです。
|
554
|
+
|
15
555
|
|
16
556
|
|
17
557
|
https://www.servernote.net/article.cgi?id=android-voice-to-text
|