我在Android中使用内置的相机应用程序使用这样的意图:
final Button Capture=(Button)findViewById(sankalp.jain.sky.R.id.capture);
Capture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri fileUri;
final Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Log.w("intent","for camera");//displayed
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
Log.w("getoutput","getit");//displayed
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
Log.w("hello","hello the 2nd step");//displayed
startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
我已经实现了相关的getOutputMediafile()方法,图像保存在/mnt/sdcard/Pictures/Samarth/chart.png中 SD卡是40MB,目前只有2个文件,总共大约100KB。
问题是相机可以完美地处理一些随机数量的快照,然后随机挂起然后给出一个ANR。 它是完全随机的,重新启动模拟器不起作用,有时也可以。
这是logcat输出
logcat的:
I/ActivityManager( 70): Displayed sankalp.jain.sky/.Tabinit: +1s364ms
W/intent ( 596): for camera
D/path ( 596): /mnt/sdcard/Pictures/Samarth
W/getoutput( 596): getit
W/hello ( 596): hello the 2nd step
I/ActivityManager( 70): Starting: Intent { act=android.media.action.IMAGE_CAPT
URE cmp=com.android.camera/.Camera (has extras) } from pid 596
D/PhoneWindow( 596): couldn't save which view has focus because the focused vie
w com.android.internal.policy.impl.PhoneWindow$DecorView@4056d7e0 has no id.
I/WindowManager( 70): Setting rotation to 1, animFlags=1
I/ActivityManager( 70): Config changed: { scale=1.0 imsi=310/260 loc=en_US tou
ch=3 keys=2/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=13}
V/CameraHolder( 411): open camera 0
D/CameraHardwareStub( 34): initHeapLocked: preview size=320x240
I/StagefrightPlayer( 34): setDataSource('/system/media/audio/ui/camera_click.o
gg')
I/StagefrightPlayer( 34): setDataSource('/system/media/audio/ui/VideoRecord.og
g')
D/Camera ( 411): app passed NULL surface
D/CameraHardwareStub( 34): initHeapLocked: preview size=320x240
V/camera ( 411): startPreview
I/ActivityManager( 70): Displayed com.android.camera/.Camera: +1s198ms
W/OrientationEventListener( 411): Cannot detect sensors. Not enabled
E/SurfaceFlinger( 70): texture=10, using format 17, which is not supported by
the GL
V/GLRootView( 411): onSurfaceChanged: 627x470, gl10: com.google.android.gles_jn
i.GLImpl@40511140
V/GLRootView( 411): layout content pane 627x470
W/IInputConnectionWrapper( 596): showStatusIcon on inactive InputConnection
D/dalvikvm( 70): GC_EXPLICIT freed 130K, 47% free 4929K/9159K, external 3511K/
4385K, paused 795ms
V/camera ( 411): Start autofocus.
D/dalvikvm( 411): GC_EXTERNAL_ALLOC freed 34K, 51% free 2932K/5895K, external 2
480K/2565K, paused 697ms
V/camera ( 411): mAutoFocusTime = 1622ms
V/camera ( 411): doSnap: mFocusState=3
D/CameraHardwareStub( 34): initHeapLocked: preview size=320x240
D/dalvikvm( 596): GC_EXPLICIT freed 209K, 49% free 2870K/5575K, external 3065K/
3507K, paused 650ms
D/SntpClient( 70): request time failed: java.net.SocketException: Address fami
ly not supported by protocol
I/InputDispatcher( 70): Application is not responding: Window{40751af8 com.and
roid.camera/com.android.camera.Camera paused=false}. 5014.6ms since event, 5014
.0ms since wait started
I/WindowManager( 70): Input event dispatching timed out sending to com.android
.camera/com.android.camera.Camera
I/Process ( 70): Sending signal. PID: 411 SIG: 3
I/dalvikvm( 411): threadid=4: reacting to signal 3
I/dalvikvm( 411): Wrote stack traces to '/data/anr/traces.txt'
I/Process ( 70): Sending signal. PID: 70 SIG: 3
I/dalvikvm( 70): threadid=4: reacting to signal 3
I/dalvikvm( 70): Wrote stack traces to '/data/anr/traces.txt'
I/Process ( 70): Sending signal. PID: 340 SIG: 3
I/dalvikvm( 340): threadid=4: reacting to signal 3
I/dalvikvm( 340): Wrote stack traces to '/data/anr/traces.txt'
I/Process ( 70): Sending signal. PID: 115 SIG: 3
I/dalvikvm( 115): threadid=4: reacting to signal 3
I/dalvikvm( 115): Wrote stack traces to '/data/anr/traces.txt'
D/dalvikvm( 70): GC_EXPLICIT freed 354K, 45% free 5052K/9159K, external 3511K/
4385K, paused 157ms
E/ActivityManager( 70): ANR in com.android.camera (com.android.camera/.Camera)
E/ActivityManager( 70): Reason: keyDispatchingTimedOut
E/ActivityManager( 70): Load: 0.12 / 0.23 / 0.25
E/ActivityManager( 70): CPU usage from 42677ms to 0ms ago:
E/ActivityManager( 70): 0.3% 70/system_server: 0.1% user + 0.1% kernel / fau
lts: 5 minor
E/ActivityManager( 70): 0.3% 115/com.android.systemui: 0.2% user + 0% kernel
/ faults: 4 minor
E/ActivityManager( 70): 0.1% 340/com.android.phone: 0% user + 0% kernel / fa
ults: 4 minor
E/ActivityManager( 70): 0% 34/mediaserver: 0% user + 0% kernel
E/ActivityManager( 70): 0% 32/rild: 0% user + 0% kernel
E/ActivityManager( 70): 0% 41/adbd: 0% user + 0% kernel
E/ActivityManager( 70): 1.1% TOTAL: 0.7% user + 0.4% kernel
E/ActivityManager( 70): CPU usage from 1031ms to 1675ms later:
E/ActivityManager( 70): 10% 70/system_server: 6.2% user + 4.6% kernel
E/ActivityManager( 70): 10% 100/InputDispatcher: 7.8% user + 3.1% kernel
E/ActivityManager( 70): 34% TOTAL: 17% user + 17% kernel
I/InputDispatcher( 70): Dropping event because the pointer is not down.
D/dalvikvm( 115): GC_CONCURRENT freed 365K, 49% free 2977K/5831K, external 2169
K/2674K, paused 9ms+6ms
D/SntpClient( 70): request time failed: java.net.SocketException: Address fami
ly not supported by protocol
W/ProcessStats( 70): Skipping unknown process pid 734
W/ProcessStats( 70): Skipping unknown process pid 735
V/BackupManagerService( 70): Backup requested but nothing pending
D/SntpClient( 70): request time failed: java.net.SocketException: Address fami
ly not supported by protocol
I/EventLogService( 266): Aggregate from 1332336498594 (log), 1332336498594 (dat
a)
D/dalvikvm( 266): GC_EXPLICIT freed 61K, 55% free 3085K/6727K, external 1625K/2
137K, paused 296ms
答案 0 :(得分:0)
我自己无法弄清楚原因,但由于某些问题,当我决定将模拟器升级到Google API15(来自API10)时,相机不再挂起。 升级还纠正了一些奇怪的问题,如
希望有人帮助。