是否有独立于包的方法来制作二维码相关的意图?
Is there a package-independant way to make a QR-code related intent?
我正在 android 应用程序中实现一项功能,该功能扫描 QR 码并使用返回的数据执行一些操作。
我目前的解决方案是从 zxing 包请求扫描 activity。
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, REQUEST_QR_SCAN);
但是,当用户的 phone 上不存在该应用程序时,这将不起作用并导致错误。我想避免检查用户是否安装了这个特定的应用程序,因为他们可能选择了不同的 QR 扫描仪。
我似乎找不到让意图说 "I want to scan a QR code" 然后允许用户选择合适的应用程序的方法。例如就像他们从图库应用程序中选择图像一样。
有什么解决办法吗?
此示例使用库 - https://github.com/dlazaro66/QRCodeReaderView
public class PayQR extends Fragment implements QRCodeReaderView.OnQRCodeReadListener {
public static QRCodeReaderView mydecoderview;
public static String QRData;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_pay_qr, container, false);
getActivity().setTitle(R.string.Pay_QR);
try {
mydecoderview = (QRCodeReaderView) view.findViewById(R.id.qrdecoderview);
mydecoderview.setOnQRCodeReadListener(this);
// Use this function to enable/disable decoding
mydecoderview.setQRDecodingEnabled(true);
// Use this function to change the autofocus interval (default is 5 secs)
mydecoderview.setAutofocusInterval(2000L);
// Use this function to enable/disable Torch
mydecoderview.setTorchEnabled(true);
// Use this function to set front camera preview
mydecoderview.setFrontCamera();
// Use this function to set back camera preview
mydecoderview.setBackCamera();
}catch (RuntimeException ex){
}
return view;
}
@Override
public void onResume() {
super.onResume();
mydecoderview.startCamera();
}
@Override
public void onQRCodeRead(String text, PointF[] points) {
try{
QRData = text.replaceAll("\u00A0"," ");
Fabric.with(getActivity(), new Crashlytics());
mydecoderview.stopCamera();
getActivity().setTitle(R.string.Order_payment);
}
catch (RuntimeException ex){
}
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
您可以在您的项目中使用 ZXing 库,通过 gradle 添加它(不幸的是只有带有 3rd-pt 的端口可用) 或者将您自己包装在应用程序中的库并声明Activity进入AndroidManifest.XML
那么您的意图将是您自己的应用程序。
此外,您可以在 ZXing 应用程序上打开 google 播放,以便用户安装它。
我正在 android 应用程序中实现一项功能,该功能扫描 QR 码并使用返回的数据执行一些操作。
我目前的解决方案是从 zxing 包请求扫描 activity。
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, REQUEST_QR_SCAN);
但是,当用户的 phone 上不存在该应用程序时,这将不起作用并导致错误。我想避免检查用户是否安装了这个特定的应用程序,因为他们可能选择了不同的 QR 扫描仪。
我似乎找不到让意图说 "I want to scan a QR code" 然后允许用户选择合适的应用程序的方法。例如就像他们从图库应用程序中选择图像一样。
有什么解决办法吗?
此示例使用库 - https://github.com/dlazaro66/QRCodeReaderView
public class PayQR extends Fragment implements QRCodeReaderView.OnQRCodeReadListener {
public static QRCodeReaderView mydecoderview;
public static String QRData;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_pay_qr, container, false);
getActivity().setTitle(R.string.Pay_QR);
try {
mydecoderview = (QRCodeReaderView) view.findViewById(R.id.qrdecoderview);
mydecoderview.setOnQRCodeReadListener(this);
// Use this function to enable/disable decoding
mydecoderview.setQRDecodingEnabled(true);
// Use this function to change the autofocus interval (default is 5 secs)
mydecoderview.setAutofocusInterval(2000L);
// Use this function to enable/disable Torch
mydecoderview.setTorchEnabled(true);
// Use this function to set front camera preview
mydecoderview.setFrontCamera();
// Use this function to set back camera preview
mydecoderview.setBackCamera();
}catch (RuntimeException ex){
}
return view;
}
@Override
public void onResume() {
super.onResume();
mydecoderview.startCamera();
}
@Override
public void onQRCodeRead(String text, PointF[] points) {
try{
QRData = text.replaceAll("\u00A0"," ");
Fabric.with(getActivity(), new Crashlytics());
mydecoderview.stopCamera();
getActivity().setTitle(R.string.Order_payment);
}
catch (RuntimeException ex){
}
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
您可以在您的项目中使用 ZXing 库,通过 gradle 添加它(不幸的是只有带有 3rd-pt 的端口可用)
那么您的意图将是您自己的应用程序。
此外,您可以在 ZXing 应用程序上打开 google 播放,以便用户安装它。