当用户点击相机时,它会在几秒钟后打开下一个屏幕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);
}
}
这是我的布局:
<?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>
我是根据这个链接http://mobile.tutsplus.com/tutorials/android/android-sdk-quick-tip-launching-the-camera/
请帮我解决问题。我的应用程序包含 Tab ActivityGroup。
提前致谢..