Dobrý den,
mám naprogramovanou vlastní kameru a chtěl bych jí spustit po stisknutí tlačítka, ale po stisknutí spadne. Chyba musí být ve startActivity(i)... Nevíte, jak ji spustit, co dělám špatně?
Přidávám zdrojové kódy:
public class FirstActivity extends Activity {
private static final int camera = 2;
private TabHost tabs;
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setTabs();
ImageButton cmr = (ImageButton) findViewById(R.id.cam);
context = this;
cmr.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(context, CameraActivity.class);
startActivity(i);
}
});
}
CameraActivity:
public class CameraActivity extends Activity {
ImageView shootBtn;
Activity context;
CameraPreview mPreview;
Camera camera;
Button exitButton;
LinearLayout progressLayout;
/**
* A safe way to get an instance of the Camera object.
*
* @return
*/
public static Camera getCameraInstance() {
Camera c = null;
try {
c = Camera.open(); // attempt to get a Camera instance
} catch (Exception e) {
// Camera is not available (in use or does not exist)
}
return c; // returns null if camera is unavailable
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mycamera);
context = this;
camera = getCameraInstance();
mPreview = new CameraPreview(context, camera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camView);
preview.addView(mPreview);
}
Předem děkuji za jakékoli rady