Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中使用意图打开文件管理器后出现红色边框_Android_Android Intent_Qr Code - Fatal编程技术网

在Android中使用意图打开文件管理器后出现红色边框

在Android中使用意图打开文件管理器后出现红色边框,android,android-intent,qr-code,Android,Android Intent,Qr Code,我正试图打开文件管理器导入二维码图像,但在使用Intent打开文件管理器并导入二维码后,我的应用程序在屏幕周围以红色边框运行。我在谷歌上搜索发现,严格模式应该被禁用,然后设备也应该被重置。但它根本不起作用。我的代码如下: @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); qrList = new Observa

我正试图打开文件管理器导入二维码图像,但在使用Intent打开文件管理器并导入二维码后,我的应用程序在屏幕周围以红色边框运行。我在谷歌上搜索发现,严格模式应该被禁用,然后设备也应该被重置。但它根本不起作用。我的代码如下:

 @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    qrList = new ObservableArrayList<>();
    bindAndAttachContentView(R.layout.ui_parkplatz, savedInstanceState);
    setSupportToolbar(binding.toolbar);
    setDrawer(binding.toolbar);

    FloatingActionButton addParkingAccessCode = findViewById(R.id.floating_action_button);
    addParkingAccessCode.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Timber.v("Click add qr code image");
            openFileManagerForQRCode();
        }
    });

    Timber.v("Enter Parkplatz activity");

    binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
    binding.recyclerView.setAdapter(new ParkplatzAdapter(qrList, this));
}


private void openFileManagerForQRCode() {
    //Intent.ACTION_GET_CONTENT
    Intent pickIntent = new Intent(Intent.ACTION_GET_CONTENT);
    pickIntent.setType("image/*");
    //pickIntent.addCategory(Intent.CATEGORY_OPENABLE);
    try{
        this.startActivityForResult(Intent.createChooser(pickIntent, "Select QRCode"), QRCODE_REQUEST);
    }catch (android.content.ActivityNotFoundException e){
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Please install a File Manager.",
                Toast.LENGTH_SHORT).show();
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);


    if (resultCode == RESULT_OK && requestCode == QRCODE_REQUEST) {
        if (data == null || data.getData() == null) {
            Timber.v("The uri is null, probably the user cancelled the image selection process using the back button.");
            return;
        }

        //SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(SHARED_PREFERENCES_QR_CODE, Context.MODE_PRIVATE);
        //SharedPreferences.Editor editor = sharedPreferences.edit();
        SQLiteDBHelper sqLiteDBHelper = new SQLiteDBHelper(getApplicationContext());

        final Uri uri = data.getData();
        String qrCodeContent = null;

        try {
            InputStream inputStream = getContentResolver().openInputStream(uri);
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

            if (bitmap == null) {
                Timber.v("URI is not a bitmap " + uri.toString());
                return;
            }

            int width = bitmap.getWidth(), height = bitmap.getHeight();
            int[] pixels = new int[width * height];
            bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
            //bitmap.recycle();
            //bitmap = null;
            //RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
            LuminanceSource source = new RGBLuminanceSource(width, height, pixels);
            BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source));
            //MultiFormatReader reader = new MultiFormatReader();
            Reader reader = new MultiFormatReader();
            Result result = null;

            try {
                result = reader.decode(bBitmap);
                qrCodeContent = result.getText();

                Timber.v("qrCode content "+qrCodeContent);
                Toast.makeText(this, "Saved QRCode", Toast.LENGTH_SHORT).show();
            } catch (NotFoundException e) {
                Timber.v("Decode exception " + e);
            } catch (FormatException e) {
                Timber.v("Decode exception " + e);
            } catch (ChecksumException e) {
                Timber.v("Decode exception " + e);
            }

            inputStream.close();
        } catch (IOException e) {
            Timber.v("Error " + e + ". Can not open file" + uri.toString());
        } finally {
            if (qrCodeContent != null) {
                //editor.putString(random(), qrCodeContent);
                //editor.commit();

                if (sqLiteDBHelper.insertQRCode(qrCodeContent)) {
                    Timber.v("Insert QRCode successful");
                } else {
                    Timber.v("Insert QRCode not successful");
                }
            }
        }
    }else{
        Timber.v("Import QRCode failed");
    }

}
@覆盖
创建时受保护的void(@Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
qrList=新的ObservableArrayList();
bindAndAttachContentView(R.layout.ui_parkplatz,savedInstanceState);
设置支持工具栏(binding.toolbar);
setDrawer(binding.toolbar);
FloatingActionButton addParkingAccessCode=findViewById(R.id.floating\u action\u按钮);
addParkingAccessCode.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Timber.v(“单击添加二维码图像”);
openFileManagerForQRCode();
}
});
Timber.v(“进入Parkplatz活动”);
binding.recyclerView.setLayoutManager(新的LinearLayoutManager(this));
binding.recyclerView.setAdapter(新的ParkPlatzaAdapter(qrList,this));
}
私有void openFileManagerForQRCode(){
//意图。行动获取内容
Intent pickIntent=新意图(Intent.ACTION\u GET\u CONTENT);
pickIntent.setType(“image/*”);
//pickIntent.addCategory(Intent.CATEGORY\u可打开);
试一试{
this.startActivityForResult(Intent.createChooser(pickIntent,“选择QRCode”),QRCode\u请求);
}捕获(android.content.ActivityNotFoundException){
//通过对话潜在地引导用户进入市场
Toast.makeText(这是“请安装文件管理器”,
吐司。长度(短)。show();
}
}
@凌驾
受保护的void onActivityResult(int-requestCode、int-resultCode、@Nullable-Intent-data){
super.onActivityResult(请求代码、结果代码、数据);
if(resultCode==RESULT\u OK&&requestCode==QRCODE\u REQUEST){
if(data==null | | data.getData()==null){
Timber.v(“uri为空,可能是用户使用后退按钮取消了图像选择过程。”);
返回;
}
//SharedReferences SharedReferences=getApplicationContext().GetSharedReferences(共享\u首选项\u QR\u代码,上下文。模式\u私有);
//SharedReferences.Editor=SharedReferences.edit();
SQLiteDBHelper SQLiteDBHelper=新的SQLiteDBHelper(getApplicationContext());
最终Uri=data.getData();
字符串qrCodeContent=null;
试一试{
InputStream InputStream=getContentResolver().openInputStream(uri);
位图位图=位图工厂.decodeStream(inputStream);
如果(位图==null){
v(“URI不是位图”+URI.toString());
返回;
}
int width=bitmap.getWidth(),height=bitmap.getHeight();
int[]像素=新int[宽度*高度];
getPixels(像素,0,宽度,0,0,宽度,高度);
//bitmap.recycle();
//位图=空;
//RGBLuminanceSource=新的RGBLuminanceSource(宽度、高度、像素);
亮度源=新的RGBLuminanceSource(宽度、高度、像素);
BinaryBitmap bBitmap=新的二进制位图(新的混合二进制程序(源));
//MultiFormatReader=新的MultiFormatReader();
Reader=新的多格式处理程序();
结果=空;
试一试{
结果=读卡器解码(bBitmap);
qrCodeContent=result.getText();
木材v(“qrCode内容”+qrCode内容);
Toast.makeText(这是“保存的QRCode”,Toast.LENGTH_SHORT).show();
}捕获(未发现异常){
木材v(“解码例外”+e);
}捕获(格式化异常){
木材v(“解码例外”+e);
}捕获(检查异常){
木材v(“解码例外”+e);
}
inputStream.close();
}捕获(IOE异常){
Timber.v(“错误“+e+”。无法打开文件“+uri.toString());
}最后{
如果(qrCodeContent!=null){
//putString(random(),qrCodeContent);
//commit();
if(sqLiteDBHelper.insertQRCode(qrCodeContent)){
Timber.v(“插入QRCode成功”);
}否则{
Timber.v(“插入QRCode不成功”);
}
}
}
}否则{
Timber.v(“进口QRCode失败”);
}
}

尝试分析
*堆栈跟踪*
输出,它将为您提供更好的想法

同时检查所有必需的权限

  • 比如管理存储文件

我已经添加了权限、写入外部存储、写入内部存储、读取外部存储,但它不起作用