我正在为我的学校开发一个应用程序,但是我无法继续使用我的display.class ...我不知道为什么它不起作用。当我点击按钮去另一个班级时,什么也没发生。
以下是我创建展示活动的意图:
Intent i = new Intent(CameraTestActivity.this, display.class);
startActivity(i);
我的AndroidManifest
<activity
android:name=".display" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我的显示活动:
package net.sourceforge.zbar.android.CameraTest;
import android.app.Activity;
import android.os.Bundle;
public class display extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.display);
}
}
谢谢
编辑:
意图似乎有效,但我的手机屏幕上没有任何内容
[2015-01-08 10:15:14 - Consomattionchecker] ActivityManager:开始:Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] cmp = net.sourceforge.zbar .android.CameraTest / .CameraTestActivity}
Edit2:CameraTestActivity代码
public class CameraTestActivity extends Activity
{
private Camera mCamera;
private CameraPreview mPreview;
private Handler autoFocusHandler;
TextView scanText;
Button scanButton;
ImageScanner scanner;
private boolean barcodeScanned = false;
private boolean previewing = true;
static {
System.loadLibrary("iconv");
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
autoFocusHandler = new Handler();
mCamera = getCameraInstance();
/* Instance barcode scanner */
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 3);
scanner.setConfig(0, Config.Y_DENSITY, 3);
mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
FrameLayout preview = (FrameLayout)findViewById(R.id.cameraPreview);
preview.addView(mPreview);
scanText = (TextView)findViewById(R.id.scanText);
scanButton = (Button)findViewById(R.id.ScanButton);
scanButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (barcodeScanned) {
barcodeScanned = false;
scanText.setText("Scanning...");
mCamera.setPreviewCallback(previewCb);
mCamera.startPreview();
previewing = true;
mCamera.autoFocus(autoFocusCB);
//------------- try
Intent i = new Intent(CameraTestActivity.this, display.class);
startActivity(i);
//-------------
}
}
});
}
@Override
public void onPause() {
super.onPause();
releaseCamera();
}
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
Camera c = null;
try {
c = Camera.open();
} catch (Exception e){
}
return c;
}
private void releaseCamera() {
if (mCamera != null) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.release();
mCamera = null;
}
}
private Runnable doAutoFocus = new Runnable() {
@Override
public void run() {
if (previewing)
mCamera.autoFocus(autoFocusCB);
}
};
PreviewCallback previewCb = new PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms) {
scanText.setText("Valeur retournée " + sym.getData());
//----------
Context context = getApplicationContext();
CharSequence text = sym.getData();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
//----------
barcodeScanned = true;
}
}
}
};
// Mimic continuous auto-focusing
AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
autoFocusHandler.postDelayed(doAutoFocus, 1000);
}
};
}
答案 0 :(得分:0)
在AndroidManifest.xml
我只能看到android:name=".display"
您还必须在其中添加其他活动
<activity
android:name=".CameraTestActivity">
</activity>
还有一件事要告诉你,
Intent i = new Intent(MyCurrenctActivity.this, ActivityIwantToMoveTo.class); // replace the names of your activities accordingly.
修改强>
您已设置private boolean barcodeScanned = false
scanButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (barcodeScanned) { // this if block never gets executed since barcodeScanned is false
barcodeScanned = false;
scanText.setText("Scanning...");
mCamera.setPreviewCallback(previewCb);
mCamera.startPreview();
previewing = true;
mCamera.autoFocus(autoFocusCB);
//------------- try
Intent i = new Intent(CameraTestActivity.this, display.class);
startActivity(i);
//-------------
}
}
});
将barcodeScanned
更改为true
private boolean barcodeScanned = true;
这是你的基本错误
答案 1 :(得分:0)
根据你的代码,你的Launcher活动应该是b CameraTestActivity和第二个活动应该显示所以你的清单文件应该像
<activity
android:name=".CameraTestActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".display" >
</activity>