当用户点击相机时,几秒后它会打开下一个屏幕。并且抛出异常Fail to connect to camera service
和cannot connect to camera
这是我使用的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View viewLoad = LayoutInflater.from(CameraActivity.this).inflate(R.layout.camera, null);
setContentView(viewLoad);
Bundle bundle = this.getIntent().getExtras();
seletctedRetailer = bundle.getString("RetailerName");
retailerCode = bundle.getString("RetailerCode");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Bundle b = new Bundle();
b.putString("Activity", "RetailerOrderSActivity");
b.putString("RetailerName", seletctedRetailer);
b.putString("RetailerCode", retailerCode);
cameraIntent.putExtras(b);
getParent().getParent().setTitle("Image Capture");
startActivityForResult(cameraIntent,CAMERA_PIC_REQUEST);
vale +=1;
Button imgMCancel =(Button)findViewById(R.id.imgMCancel);
imgMCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getBaseContext(), CameraMainActivity.class);
Bundle bundle = new Bundle();
bundle.putString("Activity", "CameraMainActivity");
bundle.putString("RetailerName", seletctedRetailer);
bundle.putString("RetailerCode", retailerCode);
i.putExtras(bundle);
View vi = SalesActivityGroup.group.getLocalActivityManager().startActivity("CameraMainActivity", i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
SalesActivityGroup.group.replaceView(vi);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == CAMERA_PIC_REQUEST) {
System.out.println("====YES======");
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(thumbnail);
}
}
layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/header"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="75dp"
android:layout_width="fill_parent">
<Button android:layout_width="wrap_content"
android:text="Cancel"
android:textColor="#FFFFFF"
android:background="@drawable/btn_red"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="150dp"
android:id="@+id/imgMCancel"
>
</Button>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttonClick"
android:text="Make Photo"
android:textColor="#FFFFFF"
android:background="@drawable/btn_red"
android:layout_gravity="center">
</Button>
</LinearLayout>
AndroidManifest.xml 文件
<activity android:name=".sales.CameraActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:clearTaskOnLaunch="false">
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
请求大家帮忙看下问题何在。我的应用程序中包含 Tab ActivityGroup。
谢谢!