问题描述
我正在尝试创建一个 Android 应用程序,它是 QR 扫描仪但具有锁定焦点。我有应用程序,但如何改变焦点?是否有可能将其设置为例如距相机 15 厘米的距离?或者放一些值来设置焦点,只是为了关闭自动对焦。
代码: 主要活动
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Camera;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private Button scan_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scan_btn = (Button) findViewById(R.id.scan_btn);
//final Activity activity = this;
scan_btn.setonClickListener(new View.OnClickListener(){
@Override
public void onClick (View view)
{
IntentIntegrator integrator = new IntentIntegrator(
MainActivity.this
);
// integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
integrator.setPrompt("Scan");
//integrator.setCameraId(0);
integrator.setBeepEnabled(true);
//integrator.setBarcodeImageEnabled(true);
integrator.setorientationLocked(true);
integrator.setCaptureActivity(Capture.class);
integrator.initiateScan();
}
});
}
@Override
protected void onActivityResult(int requestCode,int resultCode,@Nullable Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data);
if(result != null){
//chceck condition
if(result.getContents()==null){
Toast.makeText(this,"You cancelled the scanning",Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(this,result.getContents(),Toast.LENGTH_LONG).show();
}
}
else {
super.onActivityResult(requestCode,data);
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:focusable="false"
android:focusableInTouchMode="false"
>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center|center_horizontal|center_vertical"
android:text="Aplikacja do weryfikacji leków w KOWAL"
android:textSize="25dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/scan_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCAN"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
你能帮我解决这个问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)