質問編集履歴

4

コードとエラーコードを更新しました。

2016/08/26 08:09

投稿

subjectman15
subjectman15

スコア7

test CHANGED
File without changes
test CHANGED
@@ -40,57 +40,71 @@
40
40
 
41
41
  ```ここに言語を入力
42
42
 
43
- 08-24 11:13:46.255 19824-19979/パッケージ名 I/OpenGLRenderer: Initialized EGL, version 1.4
44
-
45
- 08-24 11:13:46.272 19824-19824/パッケージ名 W/CameraBase: An error occurred while connecting to camera: 0
46
-
47
- 08-24 11:13:46.275 19824-19824/パッケージ名 D/AndroidRuntime: Shutting down VM
48
-
49
- 08-24 11:13:46.275 19824-19824/パッケージ名 E/AndroidRuntime: FATAL EXCEPTION: main
50
-
51
- Process: パッケージ名, PID: 19824
52
-
53
- java.lang.RuntimeException: Fail to connect to camera service
54
-
55
- at android.hardware.Camera.<init>(Camera.java:702)
56
-
57
- at android.hardware.Camera.open(Camera.java:489)
58
-
59
- at パッケージ名.MainActivity$1.surfaceCreated(MainActivity.java:166)
60
-
61
- at android.view.SurfaceView.updateWindow(SurfaceView.java:597)
62
-
63
- at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:179)
64
-
65
- at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
66
-
67
- at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2073)
68
-
69
- at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1125)
70
-
71
- at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6058)
72
-
73
- at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
74
-
75
- at android.view.Choreographer.doCallbacks(Choreographer.java:670)
76
-
77
- at android.view.Choreographer.doFrame(Choreographer.java:606)
78
-
79
- at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
80
-
81
- at android.os.Handler.handleCallback(Handler.java:739)
82
-
83
- at android.os.Handler.dispatchMessage(Handler.java:95)
84
-
85
- at android.os.Looper.loop(Looper.java:148)
86
-
87
- at android.app.ActivityThread.main(ActivityThread.java:5554)
88
-
89
- at java.lang.reflect.Method.invoke(Native Method)
90
-
91
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
92
-
93
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
43
+ 08-26 17:04:36.424 6846-6846パッケージ名 I/Process: Sending signal. PID: 6846 SIG: 9
44
+
45
+ 08-26 17:04:37.671 6940-6940パッケージ名 W/System: ClassLoader referenced unknown path: /data/appパッケージ名-1/lib/arm64
46
+
47
+ 08-26 17:04:37.773 6940-6940パッケージ名 W/System: ClassLoader referenced unknown path: /data/appパッケージ名-1/lib/arm64
48
+
49
+ 08-26 17:04:37.827 6940-6940パッケージ名 D/AndroidRuntime: Shutting down VM
50
+
51
+ 08-26 17:04:37.827 6940-6940パッケージ名 E/AndroidRuntime: FATAL EXCEPTION: main
52
+
53
+ Process: パッケージ名, PID: 6940
54
+
55
+ java.lang.RuntimeException: Unable to start activity ComponentInfo{パッケージ名パッケージ名.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
56
+
57
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2455)
58
+
59
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2541)
60
+
61
+ at android.app.ActivityThread.access$900(ActivityThread.java:169)
62
+
63
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
64
+
65
+ at android.os.Handler.dispatchMessage(Handler.java:102)
66
+
67
+ at android.os.Looper.loop(Looper.java:148)
68
+
69
+ at android.app.ActivityThread.main(ActivityThread.java:5554)
70
+
71
+ at java.lang.reflect.Method.invoke(Native Method)
72
+
73
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
74
+
75
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
76
+
77
+ Caused by: java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
78
+
79
+ at パッケージ名.MainActivity.requestPermissions(MainActivity.java:123)
80
+
81
+ at パッケージ名.MainActivity.checkPermission(MainActivity.java:112)
82
+
83
+ at パッケージ名.MainActivity.onCreate(MainActivity.java:50)
84
+
85
+ at android.app.Activity.performCreate(Activity.java:6285)
86
+
87
+ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
88
+
89
+ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
90
+
91
+ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2541) 
92
+
93
+ at android.app.ActivityThread.access$900(ActivityThread.java:169) 
94
+
95
+ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382) 
96
+
97
+ at android.os.Handler.dispatchMessage(Handler.java:102) 
98
+
99
+ at android.os.Looper.loop(Looper.java:148) 
100
+
101
+ at android.app.ActivityThread.main(ActivityThread.java:5554) 
102
+
103
+ at java.lang.reflect.Method.invoke(Native Method) 
104
+
105
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746) 
106
+
107
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 
94
108
 
95
109
 
96
110
 
@@ -156,6 +170,14 @@
156
170
 
157
171
  super.onCreate( savedInstanceState );
158
172
 
173
+ File dirs = new File( "storage" );
174
+
175
+ if (!dirs.exists()) {
176
+
177
+ dirs.mkdir();
178
+
179
+ }
180
+
159
181
 
160
182
 
161
183
 
@@ -198,11 +220,121 @@
198
220
 
199
221
 
200
222
 
223
+
224
+
225
+ }
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+ private boolean checkPermission() {
236
+
237
+ boolean camP;
238
+
239
+
240
+
241
+ boolean recP;
242
+
243
+
244
+
245
+ boolean strP;
246
+
247
+
248
+
249
+
250
+
251
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED) {
252
+
253
+ camP=false;
254
+
255
+ }else {
256
+
257
+ camP=true;
258
+
259
+ }
260
+
261
+
262
+
263
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.RECORD_AUDIO ) != PackageManager.PERMISSION_GRANTED) {
264
+
265
+ recP=false;
266
+
267
+ }else {
268
+
269
+ recP=true;
270
+
271
+ }
272
+
273
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED) {
274
+
275
+
276
+
277
+ strP=false;
278
+
279
+ }else {
280
+
281
+ strP=true;
282
+
283
+ }
284
+
285
+
286
+
287
+ requestPermissions(camP,recP,strP);
288
+
201
- File dirs = new File( "storage" );
289
+ Log.v( "request","permission" );
290
+
202
-
291
+ return camP && recP && strP;
292
+
293
+
294
+
295
+ }
296
+
297
+
298
+
299
+
300
+
301
+ private void requestPermissions(boolean camP, boolean recP, boolean strP) {
302
+
303
+ boolean pList[]= new boolean[2];
304
+
305
+ pList[0] = camP;
306
+
307
+ pList[1] = recP;
308
+
309
+ pList[2] = strP;
310
+
311
+
312
+
313
+ for (int i=0;i<pList.length;i++){
314
+
203
- if (!dirs.exists()) {
315
+ if (pList[i]){
204
-
316
+
205
- dirs.mkdir();
317
+ switch (i){
318
+
319
+ case 0:
320
+
321
+ ActivityCompat.requestPermissions( MainActivity.this, new String[]{Manifest.permission.CAMERA}, REQUEST_PERMISSION );
322
+
323
+ break;
324
+
325
+ case 1:
326
+
327
+ ActivityCompat.requestPermissions( MainActivity.this, new String[]{Manifest.permission.RECORD_AUDIO}, REQUEST_PERMISSION );
328
+
329
+ break;
330
+
331
+ case 2:
332
+
333
+ ActivityCompat.requestPermissions( MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
334
+
335
+ break;
336
+
337
+ }
206
338
 
207
339
  }
208
340
 
@@ -212,93 +344,35 @@
212
344
 
213
345
 
214
346
 
215
-
216
-
217
-
218
-
219
- private boolean checkPermission() {
220
-
221
- boolean camP;
222
-
223
-
224
-
225
- boolean recP;
226
-
227
-
228
-
229
- boolean strP;
230
-
231
-
232
-
233
-
234
-
235
- if (ActivityCompat.checkSelfPermission( this, Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED) {
236
-
237
- camP=false;
238
-
239
- }else {
240
-
241
- camP=true;
242
-
243
- }
244
-
245
-
246
-
247
- if (ActivityCompat.checkSelfPermission( this, Manifest.permission.RECORD_AUDIO ) != PackageManager.PERMISSION_GRANTED) {
248
-
249
- recP=false;
250
-
251
- }else {
252
-
253
- recP=true;
254
-
255
- }
256
-
257
- if (ActivityCompat.checkSelfPermission( this, Manifest.permission.WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED) {
258
-
259
-
260
-
261
- strP=false;
262
-
263
- }else {
264
-
265
- strP=true;
266
-
267
- }
268
-
269
-
270
-
271
- requestPermissions(camP,recP,strP);
272
-
273
- Log.v( "request","permission" );
274
-
275
- return camP && recP && strP;
276
-
277
-
278
-
279
347
  }
280
348
 
281
349
 
282
350
 
283
351
 
284
352
 
285
- private void requestPermissions(boolean camP, boolean recP, boolean strP) {
286
-
287
-
288
-
289
- if (ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.CAMERA )) {
290
-
291
- ActivityCompat.requestPermissions( MainActivity.this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
292
-
293
- } else {
294
-
295
- ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
296
-
297
- }
298
-
299
-
300
-
301
-
353
+
354
+
355
+
356
+
357
+ @Override
358
+
359
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
360
+
361
+ if (requestCode == REQUEST_PERMISSION) {
362
+
363
+ // 使用が許可された
364
+
365
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
366
+
367
+ prepareCamera();
368
+
369
+ return;
370
+
371
+
372
+
373
+ }
374
+
375
+ }
302
376
 
303
377
  }
304
378
 
@@ -308,32 +382,6 @@
308
382
 
309
383
 
310
384
 
311
-
312
-
313
- @Override
314
-
315
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
316
-
317
- if (requestCode == REQUEST_PERMISSION) {
318
-
319
- // 使用が許可された
320
-
321
- if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
322
-
323
- prepareCamera();
324
-
325
- return;
326
-
327
-
328
-
329
- }
330
-
331
- }
332
-
333
- }
334
-
335
-
336
-
337
385
  以下文字数の関係で省略。
338
386
 
339
387
 

3

8/25現在のコードに更新しました。

2016/08/26 08:09

投稿

subjectman15
subjectman15

スコア7

test CHANGED
File without changes
test CHANGED
@@ -144,198 +144,196 @@
144
144
 
145
145
  protected void onCreate(Bundle savedInstanceState) {
146
146
 
147
- if (Build.VERSION.SDK_INT >= 23) {
147
+
148
-
148
+
149
- checkPermission();
149
+ checkPermission();
150
-
150
+
151
- Log.v( "Check","permission" );
151
+ Log.v( "Check", "permission" );
152
+
153
+
154
+
155
+
156
+
152
-
157
+ super.onCreate( savedInstanceState );
158
+
159
+
160
+
161
+
162
+
153
-
163
+ }
164
+
165
+ private void prepareCamera(){
166
+
167
+ setContentView( R.layout.activity_main );
168
+
169
+ btn1 = (Button) findViewById( R.id.button1 );
170
+
171
+ btn1.setOnClickListener( this );
172
+
173
+
174
+
175
+ btn2 = (Button) findViewById( R.id.rebtn );
176
+
177
+ btn2.setOnClickListener( this );
178
+
179
+
180
+
181
+ mySurfaceView = (SurfaceView) findViewById( R.id.surface_view );
182
+
183
+
184
+
185
+ holder = mySurfaceView.getHolder();
186
+
187
+
188
+
189
+ holder.addCallback( callback );
190
+
191
+ Log.v( "Holder", "ok" );
192
+
193
+ holder.setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
194
+
195
+ Log.v( TAG, "Holder" + holder );
196
+
197
+
198
+
199
+
200
+
201
+ File dirs = new File( "storage" );
202
+
203
+ if (!dirs.exists()) {
204
+
205
+ dirs.mkdir();
206
+
207
+ }
208
+
209
+ }
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+ private boolean checkPermission() {
220
+
221
+ boolean camP;
222
+
223
+
224
+
225
+ boolean recP;
226
+
227
+
228
+
229
+ boolean strP;
230
+
231
+
232
+
233
+
234
+
235
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED) {
236
+
237
+ camP=false;
154
238
 
155
239
  }else {
156
240
 
157
-
158
-
159
-
160
-
161
-
162
-
163
- super.onCreate( savedInstanceState );
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
- setContentView( R.layout.activity_main );
172
-
173
- btn1 = (Button) findViewById( R.id.button1 );
174
-
175
- btn1.setOnClickListener( this );
176
-
177
-
178
-
179
- btn2 = (Button) findViewById( R.id.rebtn );
180
-
181
- btn2.setOnClickListener( this );
182
-
183
-
184
-
185
- mySurfaceView = (SurfaceView) findViewById( R.id.surface_view );
186
-
187
-
188
-
189
- holder = mySurfaceView.getHolder();
190
-
191
-
192
-
193
- holder.addCallback( callback );
194
-
195
- Log.v( "Holder", "ok" );
196
-
197
- holder.setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
198
-
199
- Log.v( TAG, "Holder" + holder );
200
-
201
-
202
-
203
-
204
-
205
- File dirs = new File( "storage" );
206
-
207
- if (!dirs.exists()) {
208
-
209
- dirs.mkdir();
241
+ camP=true;
242
+
243
+ }
244
+
245
+
246
+
247
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.RECORD_AUDIO ) != PackageManager.PERMISSION_GRANTED) {
248
+
249
+ recP=false;
250
+
251
+ }else {
252
+
253
+ recP=true;
254
+
255
+ }
256
+
257
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED) {
258
+
259
+
260
+
261
+ strP=false;
262
+
263
+ }else {
264
+
265
+ strP=true;
266
+
267
+ }
268
+
269
+
270
+
271
+ requestPermissions(camP,recP,strP);
272
+
273
+ Log.v( "request","permission" );
274
+
275
+ return camP && recP && strP;
276
+
277
+
278
+
279
+ }
280
+
281
+
282
+
283
+
284
+
285
+ private void requestPermissions(boolean camP, boolean recP, boolean strP) {
286
+
287
+
288
+
289
+ if (ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.CAMERA )) {
290
+
291
+ ActivityCompat.requestPermissions( MainActivity.this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
292
+
293
+ } else {
294
+
295
+ ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
296
+
297
+ }
298
+
299
+
300
+
301
+
302
+
303
+ }
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+ @Override
314
+
315
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
316
+
317
+ if (requestCode == REQUEST_PERMISSION) {
318
+
319
+ // 使用が許可された
320
+
321
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
322
+
323
+ prepareCamera();
324
+
325
+ return;
326
+
327
+
210
328
 
211
329
  }
212
330
 
213
331
  }
214
332
 
215
-
216
-
217
333
  }
218
334
 
219
335
 
220
336
 
221
-
222
-
223
- private boolean checkPermission() {
224
-
225
- boolean camP;
226
-
227
-
228
-
229
- boolean recP;
230
-
231
-
232
-
233
- boolean strP;
234
-
235
-
236
-
237
-
238
-
239
- if (ActivityCompat.checkSelfPermission( this, Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED) {
240
-
241
- camP=false;
242
-
243
- }else {
244
-
245
- camP=true;
246
-
247
- }
248
-
249
-
250
-
251
- if (ActivityCompat.checkSelfPermission( this, Manifest.permission.RECORD_AUDIO ) != PackageManager.PERMISSION_GRANTED) {
252
-
253
- recP=false;
254
-
255
- }else {
256
-
257
- recP=true;
258
-
259
- }
260
-
261
- if (ActivityCompat.checkSelfPermission( this, Manifest.permission.WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED) {
262
-
263
-
264
-
265
- strP=false;
266
-
267
- }else {
268
-
269
- strP=true;
270
-
271
- }
272
-
273
-
274
-
275
- requestPermissions(camP,recP,strP);
276
-
277
- Log.v( "request","permission" );
278
-
279
- return camP && recP && strP;
280
-
281
- }
282
-
283
-
284
-
285
-
286
-
287
- private void requestPermissions(boolean camP, boolean recP, boolean strP) {
288
-
289
-
290
-
291
- if (ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.CAMERA )) {
292
-
293
- ActivityCompat.requestPermissions( MainActivity.this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
294
-
295
- } else {
296
-
297
- ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
298
-
299
- }
300
-
301
-
302
-
303
-
304
-
305
- }
306
-
307
-
308
-
309
-
310
-
311
-
312
-
313
-
314
-
315
- @Override
316
-
317
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
318
-
319
- if (requestCode == REQUEST_PERMISSION) {
320
-
321
- // 使用が許可された
322
-
323
- if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
324
-
325
- return;
326
-
327
-
328
-
329
- }
330
-
331
- }
332
-
333
- }
334
-
335
-
336
-
337
-
338
-
339
337
  以下文字数の関係で省略。
340
338
 
341
339
 

2

8/25現在のコードに変更しました。

2016/08/25 08:47

投稿

subjectman15
subjectman15

スコア7

test CHANGED
File without changes
test CHANGED
@@ -104,6 +104,8 @@
104
104
 
105
105
  ```ここに言語を入力
106
106
 
107
+
108
+
107
109
  public class MainActivity extends Activity implements View.OnClickListener {
108
110
 
109
111
  private SurfaceView mySurfaceView;
@@ -130,69 +132,83 @@
130
132
 
131
133
 
132
134
 
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
133
143
  @Override
134
144
 
135
145
  protected void onCreate(Bundle savedInstanceState) {
136
146
 
137
- if(Build.VERSION.SDK_INT >= 23){
147
+ if (Build.VERSION.SDK_INT >= 23) {
138
148
 
139
149
  checkPermission();
140
150
 
141
- }
142
-
143
-
144
-
145
- super.onCreate( savedInstanceState );
146
-
147
- setContentView( R.layout.activity_main );
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
- btn1 = (Button) findViewById( R.id.button1 );
160
-
161
- btn1.setOnClickListener( this );
162
-
163
-
164
-
165
- btn2 = (Button) findViewById( R.id.rebtn );
166
-
167
- btn2.setOnClickListener( this );
168
-
169
-
170
-
171
- mySurfaceView = (SurfaceView) findViewById( R.id.surface_view );
172
-
173
-
174
-
175
- holder = mySurfaceView.getHolder();
176
-
177
-
178
-
179
- holder.addCallback( callback );
180
-
181
- Log.v("Holder","ok");
182
-
183
- holder.setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
184
-
185
- Log.v(TAG,"Holder"+holder);
186
-
187
-
188
-
189
-
190
-
191
- File dirs = new File( "storage" );
192
-
193
- if (!dirs.exists()) {
194
-
195
- dirs.mkdir();
151
+ Log.v( "Check","permission" );
152
+
153
+
154
+
155
+ }else {
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+ super.onCreate( savedInstanceState );
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ setContentView( R.layout.activity_main );
172
+
173
+ btn1 = (Button) findViewById( R.id.button1 );
174
+
175
+ btn1.setOnClickListener( this );
176
+
177
+
178
+
179
+ btn2 = (Button) findViewById( R.id.rebtn );
180
+
181
+ btn2.setOnClickListener( this );
182
+
183
+
184
+
185
+ mySurfaceView = (SurfaceView) findViewById( R.id.surface_view );
186
+
187
+
188
+
189
+ holder = mySurfaceView.getHolder();
190
+
191
+
192
+
193
+ holder.addCallback( callback );
194
+
195
+ Log.v( "Holder", "ok" );
196
+
197
+ holder.setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
198
+
199
+ Log.v( TAG, "Holder" + holder );
200
+
201
+
202
+
203
+
204
+
205
+ File dirs = new File( "storage" );
206
+
207
+ if (!dirs.exists()) {
208
+
209
+ dirs.mkdir();
210
+
211
+ }
196
212
 
197
213
  }
198
214
 
@@ -202,31 +218,65 @@
202
218
 
203
219
 
204
220
 
221
+
222
+
205
- private void checkPermission() {
223
+ private boolean checkPermission() {
224
+
206
-
225
+ boolean camP;
226
+
227
+
228
+
229
+ boolean recP;
230
+
231
+
232
+
233
+ boolean strP;
234
+
235
+
236
+
237
+
238
+
207
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED){
239
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED) {
208
-
240
+
209
- requestCamPermission();
241
+ camP=false;
242
+
210
-
243
+ }else {
244
+
245
+ camP=true;
246
+
211
- }
247
+ }
212
-
213
-
214
-
248
+
249
+
250
+
215
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)!= PackageManager.PERMISSION_GRANTED){
251
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.RECORD_AUDIO ) != PackageManager.PERMISSION_GRANTED) {
216
-
252
+
217
- requestRecPermission();
253
+ recP=false;
254
+
218
-
255
+ }else {
256
+
257
+ recP=true;
258
+
219
- }
259
+ }
220
-
221
-
222
-
260
+
223
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED){
261
+ if (ActivityCompat.checkSelfPermission( this, Manifest.permission.WRITE_EXTERNAL_STORAGE ) != PackageManager.PERMISSION_GRANTED) {
224
-
262
+
263
+
264
+
225
- requestWritePermission();
265
+ strP=false;
266
+
226
-
267
+ }else {
268
+
269
+ strP=true;
270
+
227
- }
271
+ }
272
+
273
+
274
+
228
-
275
+ requestPermissions(camP,recP,strP);
276
+
229
-
277
+ Log.v( "request","permission" );
278
+
279
+ return camP && recP && strP;
230
280
 
231
281
  }
232
282
 
@@ -234,17 +284,21 @@
234
284
 
235
285
 
236
286
 
237
- private void requestCamPermission() {
238
-
239
- if (ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.CAMERA)){
240
-
241
- ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA},REQUEST_PERMISSION);
242
-
243
- }else {
244
-
245
- ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CAMERA},REQUEST_PERMISSION);
246
-
247
- }
287
+ private void requestPermissions(boolean camP, boolean recP, boolean strP) {
288
+
289
+
290
+
291
+ if (ActivityCompat.shouldShowRequestPermissionRationale( this, Manifest.permission.CAMERA )) {
292
+
293
+ ActivityCompat.requestPermissions( MainActivity.this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
294
+
295
+ } else {
296
+
297
+ ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION );
298
+
299
+ }
300
+
301
+
248
302
 
249
303
 
250
304
 
@@ -252,15 +306,27 @@
252
306
 
253
307
 
254
308
 
309
+
310
+
311
+
312
+
313
+
314
+
255
- private void requestRecPermission() {
315
+ @Override
256
-
257
- if (ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.RECORD_AUDIO)){
316
+
258
-
259
- ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.RECORD_AUDIO},REQUEST_PERMISSION);
317
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
318
+
260
-
319
+ if (requestCode == REQUEST_PERMISSION) {
320
+
321
+ // 使用が許可された
322
+
323
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
324
+
261
- }else {
325
+ return;
262
-
326
+
327
+
328
+
263
- ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.RECORD_AUDIO},REQUEST_PERMISSION);
329
+ }
264
330
 
265
331
  }
266
332
 
@@ -268,56 +334,6 @@
268
334
 
269
335
 
270
336
 
271
- private void requestWritePermission() {
272
-
273
- if (ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.WRITE_EXTERNAL_STORAGE)){
274
-
275
- ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_PERMISSION);
276
-
277
- }else {
278
-
279
- ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_PERMISSION);
280
-
281
- }
282
-
283
-
284
-
285
- }
286
-
287
-
288
-
289
- @Override
290
-
291
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
292
-
293
- if (requestCode == REQUEST_PERMISSION) {
294
-
295
- // 使用が許可された
296
-
297
- if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
298
-
299
- Camera.open();
300
-
301
- return;
302
-
303
-
304
-
305
- } else {
306
-
307
- // それでも拒否された時の対応
308
-
309
- Toast toast = Toast.makeText(this, "これ以上なにもできません", Toast.LENGTH_SHORT);
310
-
311
- toast.show();
312
-
313
- }
314
-
315
- }
316
-
317
- }
318
-
319
-
320
-
321
337
 
322
338
 
323
339
  以下文字数の関係で省略。

1

エラーログを追記しました。

2016/08/25 06:25

投稿

subjectman15
subjectman15

スコア7

test CHANGED
File without changes
test CHANGED
@@ -36,6 +36,70 @@
36
36
 
37
37
 
38
38
 
39
+ 以下エラーログです。
40
+
41
+ ```ここに言語を入力
42
+
43
+ 08-24 11:13:46.255 19824-19979/パッケージ名 I/OpenGLRenderer: Initialized EGL, version 1.4
44
+
45
+ 08-24 11:13:46.272 19824-19824/パッケージ名 W/CameraBase: An error occurred while connecting to camera: 0
46
+
47
+ 08-24 11:13:46.275 19824-19824/パッケージ名 D/AndroidRuntime: Shutting down VM
48
+
49
+ 08-24 11:13:46.275 19824-19824/パッケージ名 E/AndroidRuntime: FATAL EXCEPTION: main
50
+
51
+ Process: パッケージ名, PID: 19824
52
+
53
+ java.lang.RuntimeException: Fail to connect to camera service
54
+
55
+ at android.hardware.Camera.<init>(Camera.java:702)
56
+
57
+ at android.hardware.Camera.open(Camera.java:489)
58
+
59
+ at パッケージ名.MainActivity$1.surfaceCreated(MainActivity.java:166)
60
+
61
+ at android.view.SurfaceView.updateWindow(SurfaceView.java:597)
62
+
63
+ at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:179)
64
+
65
+ at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
66
+
67
+ at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2073)
68
+
69
+ at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1125)
70
+
71
+ at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6058)
72
+
73
+ at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
74
+
75
+ at android.view.Choreographer.doCallbacks(Choreographer.java:670)
76
+
77
+ at android.view.Choreographer.doFrame(Choreographer.java:606)
78
+
79
+ at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
80
+
81
+ at android.os.Handler.handleCallback(Handler.java:739)
82
+
83
+ at android.os.Handler.dispatchMessage(Handler.java:95)
84
+
85
+ at android.os.Looper.loop(Looper.java:148)
86
+
87
+ at android.app.ActivityThread.main(ActivityThread.java:5554)
88
+
89
+ at java.lang.reflect.Method.invoke(Native Method)
90
+
91
+ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
92
+
93
+ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
94
+
95
+
96
+
97
+ ```
98
+
99
+
100
+
101
+
102
+
39
103
  ###該当のソースコード
40
104
 
41
105
  ```ここに言語を入力