当前位置: 首页 > 知识库问答 >
问题:

Android:被撤销的权限

沃念
2023-03-14

好的一天,我正试图让应用程序捕捉图像,然后在gridview中显示它,但当我单击按钮开始捕捉时,这个错误出现了。

logcat:

java.lang.SecurityException: Permission Denial: starting Intent {
act=android.media.action.IMAGE_CAPTURE flg=0x3
cmp=com.android.camera2/com.android.camera.CaptureActivity
clip={text/uri-list
U:file:///storage/emulated/0/Pictures/MyInvoice/IMG_20160223_032401.jpg}
(has extras) } from ProcessRecord{8f9b88f
1356:com.example.labon.invoicemanger/u0a62} (pid=1356, uid=10062) with
revoked permission android.permission.CAMERA
at android.os.Parcel.readException(Parcel.java:1599)

我的代码:

    myLists = new ArrayList<Images>();
    adapter = new ImageListAdapter(getActivity(), R.layout.img_list_view, myLists);
    Button myButton = (Button) view.findViewById(R.id.camerabutton);
    myButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);// create a file to save the image
            intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
            startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE); // start the image capture Intent
        }
    });
    myGridView = (GridView) view.findViewById(R.id.gridView);
    myGridView.setAdapter(adapter);   /**
 * Create a file Uri for saving an image or video
 */
public Uri getOutputMediaFileUri(int type) {

    return Uri.fromFile(getOutputMediaFile(type));
}
/**
 * returning image /
 */
private static File getOutputMediaFile(int type) {

    // External sdcard location
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), IMAGE_DIRECTORY_NAME);

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        mediaStorageDir.mkdirs();
        // if (!mediaStorageDir.mkdirs()) {
        Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
                + IMAGE_DIRECTORY_NAME + " directory");
        //return null;

    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
            Locale.getDefault()).format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator
                + "IMG_" + timeStamp + ".jpg");
    } else {
        return null;
    }


    return mediaFile;


}


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


    switch (requestCode) {
        case 1:
            if (resultCode == Activity.RESULT_OK) {
                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};
                Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                //file path of captured image
                String filePath = cursor.getString(columnIndex);
                //file path of captured image
                File f = new File(filePath);
                String filename = f.getName();
                cursor.close();

                //Convert file path into bitmap image using below line.
                Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
                //put bitmapimage in your imageview
                ImageView imageView = (ImageView) view.findViewById(R.id.imageListView);
                imageView.setImageBitmap(BitmapFactory.decodeByteArray(images.getImageBlob(), 0, images.getImageBlob().length));
                //newImageView.setImageBitmap(yourSelectedImage);  }
    if (resultCode == getActivity().RESULT_CANCELED) {
        // user cancelled Image capture
        Toast.makeText(getActivity(), "User cancelled image capture", Toast.LENGTH_SHORT)
                .show();
    } else {
        // failed to capture image
        Toast.makeText(getActivity(), "Sorry! Failed to capture image", Toast.LENGTH_SHORT)
                .show();
    }
} }

共有1个答案

唐修明
2023-03-14

你是在Marshmallow上运行这个吗?因为如果是,权限结构已经改变。您应该阅读文档@http://developer.android.com/training/permissions/index.html。

用户必须显式授予权限。

 类似资料:
  • 问题内容: 我们正在合理化数据库用户的权限,为此,我们希望撤销授予所有用户(但不是特定角色)的架构中所有表的所有选择权限。 我尝试使用一些正则表达式为每个表创建一个通用表,使其类似于: 从USER1,USER2,USER3 …撤消对TABLE1的选择; 从USER1,USER2,USER3 …撤消对TABLE2的选择; 但是,由于并非所有用户都被授予了对所有表的权限,因此会导致oracle错误:

  • 本文向大家介绍Postgresql 赋予用户权限和撤销权限的实例,包括了Postgresql 赋予用户权限和撤销权限的实例的使用技巧和注意事项,需要的朋友参考一下 1、对数据库授权 postgresql 授权某个数据库的权限给wang 账号 使该账号 只能操作指定DB 不能操作其他DB 配置权限 对表授权 撤销授权 撤销对数据库授权 撤销对表授权 对当前库中所有表去掉public的所有访问权限,为

  • 问题内容: 当我为用户授予某些特定表的特权时: 我如何撤销仅此用户的特权? 问题答案: Google是您的朋友! http://dev.mysql.com/doc/refman/5.7/en/revoke.html 句法: 为了进一步解释这个答案-我将教如何钓鱼(而不是只给你一条鱼)。 首先,MySQL文档可能看起来令人困惑-“语法”如下所示: 这意味着有3种“方式”来称呼它: 这三个用MySQL

  • 目前只有 刷卡支付 有此功能。 调用支付接口后请勿立即调用撤销订单API,建议支付后至少15s后再调用撤销订单接口。 通过内部订单号撤销订单 $app->reverse->byOutTradeNumber("商户系统内部的订单号(out_trade_no)"); 通过微信订单号撤销订单 $app->reverse->byTransactionId("微信的订单号(transaction_id)"

  • 说明 微信支付撤销订单SDK。 官方文档:https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_11&index=3 类 请求参数类 请求参数 类名:\Yurun\PaySDK\Weixin\Reverse\Request 属性 名称 类型 说明 $_apiMethod string 接口名称 $transaction_id s