Android 6.01給出「不幸的是,相機已停止」錯誤,如果我們旋轉我們的手機,而視頻capture.this只發生在Android 6.01 update.all其他Android視覺捕獲開始後鎖定相機。但是如果我們旋轉手機,android 6.01相機會旋轉。這在默認相機中不會發生。僅當我們使用Intent捕捉視頻時纔會發生這種情況。不幸的是,相機已停止錯誤在Android 6.01
activity_video_app_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".VideoAppMainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record"
android:id="@+id/recordButton"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:id="@+id/playButton"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:singleLine="true" />
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/videoView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_above="@+id/recordButton" />
VideoAppMainActivity
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;
public class VideoAppMainActivity extends Activity {
private Button mRecordView, mPlayView;
private VideoView mVideoView;
private int ACTIVITY_START_CAMERA_APP = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_app_main);
mRecordView = (Button) findViewById(R.id.recordButton);
mPlayView = (Button) findViewById(R.id.playButton);
mVideoView = (VideoView) findViewById(R.id.videoView);
mRecordView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent callVideoAppIntent = new Intent();
callVideoAppIntent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(callVideoAppIntent, ACTIVITY_START_CAMERA_APP);
}
});
mPlayView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mVideoView.start();
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == ACTIVITY_START_CAMERA_APP && resultCode == RESULT_OK) {
Uri videoUri = data.getData();
mVideoView.setVideoURI(videoUri);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_video_app_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
menu_video_app_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".VideoAppMainActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" android:showAsAction="never" />
</menu>
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nigelhenshaw.com.videoapp" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".VideoAppMainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
的strings.xml
<resources>
<string name="app_name">VideoApp</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>
嘗試到您的應用程序的權限 可能ü沒有權限訪問 –
「如果我們在視頻捕捉時旋轉手機,「Android 6.01給出了」不幸的是,相機已停止「錯誤 - 除非您的應用程序被命名爲」相機「,否則無論相機應用程序是否處理您的請求,都會發現錯誤。對此你幾乎沒有辦法。 – CommonsWare
這不是權限問題 – heshjse