zoukankan      html  css  js  c++  java
  • android 6.0权限判断 音频 拍照 相册

    ------------------------------------------打开音频权限------------------------------------------------
                    if (PackageManager.PERMISSION_GRANTED ==   ContextCompat.
                            checkSelfPermission(context, android.Manifest.permission.RECORD_AUDIO)) {
    }else{
                        //提示用户开户权限音频
                        String[] perms = {"android.permission.RECORD_AUDIO"};
                        ActivityCompat.requestPermissions(ChatActivity.this,perms, RESULT_CODE_STARTAUDIO);
                    }
    @Override
        public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults){
            switch(permsRequestCode){
            case RESULT_CODE_STARTAUDIO:
                    boolean albumAccepted = grantResults[0]==PackageManager.PERMISSION_GRANTED;
                    if(!albumAccepted){
    
                        ToastUtil.show(context,"请开启应用录音权限");
                    }
                    break;
            }
        }
    ------------------------------------------打开拍照权限------------------------------------------------
    //判断是否开户相册权限
                                    if (PackageManager.PERMISSION_GRANTED ==   ContextCompat.checkSelfPermission(context, android.Manifest.permission.CAMERA)) {
    
                                        Camera.startCameraUrl(context, filename, CAMERA);
                                    }else{
                                        //提示用户开户权限
                                        String[] perms = {"android.permission.CAMERA"};
                                        ActivityCompat.requestPermissions(Broadcast_publish.this,perms, RESULT_CODE_STARTCAMERA);
                                    }
    
    
        @Override
        public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults){
            switch(permsRequestCode){
                case RESULT_CODE_STARTCAMERA:
                    boolean cameraAccepted = grantResults[0]==PackageManager.PERMISSION_GRANTED;
                    if(cameraAccepted){
                        //授权成功之后,调用系统相机进行拍照操作等
                        Camera.startCameraUrl(context, filename, CAMERA);
                    }else{
                        //用户授权拒绝之后,友情提示一下就可以了
                        ToastUtil.show(context,"请开启应用拍照权限");
                    }
                    break;
    }
    }
    
    ------------------------------------------打开相册权限------------------------------------------------
    if (PackageManager.PERMISSION_GRANTED ==   ContextCompat.
                                            checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                        Intent intent = new Intent(context, PhotoAlbumActivity.class);
                                        context.startActivity(intent);
                                    }else{
                                        //提示用户开户权限
                                        String[] perms = {"android.permission.WRITE_EXTERNAL_STORAGE"};
                                        ActivityCompat.requestPermissions(Broadcast_publish.this,perms, RESULT_CODE_STARTSTORAGE);
                                    }
    
    @Override
        public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults){
            switch(permsRequestCode){ 
                case RESULT_CODE_STARTSTORAGE:
                    boolean albumAccepted = grantResults[0]==PackageManager.PERMISSION_GRANTED;
                    if(albumAccepted){
                        Intent intent = new Intent(context, PhotoAlbumActivity.class);
                        context.startActivity(intent);
                    }else{
                        //用户授权拒绝之后,友情提示一下就可以了
                        ToastUtil.show(context,"请开启应用拍照权限");
                    }
                    break;
            }
        }
  • 相关阅读:
    C++类的内存结构
    emplace与insert的区别(C++11)
    C/C++宏的奇技淫巧
    编译器对内存的分配
    利用C++实现模块隐藏(R3层断链)
    PCB标准规范
    RTC 总结
    0.96寸OLED显示屏 IIC接口(SSD1306)
    串行通信简介(SPI, IIC, UART)
    人生感悟
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/5974743.html
Copyright © 2011-2022 走看看