Android权限对话框不会出现

时间:2017-03-16 14:03:23

标签: android

我有电话号码活动以及电话号码控制器类 我已经在我的标准方法中定义了checkpermission和requestpermission,并从控制器类调用它们,如下所示:

public static boolean checkPermission ( Context context ) {
    Log.e ( "checkPermission: " + context.getClass ( ) );
    if (ContextCompat.checkSelfPermission (context,
          Manifest.permission.READ_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED)
        return true;
    return false;

public static void requestPermission ( Activity activity ) {
        Log.e ( "AA---->>>", "requestPermission: " + activity.getClass ( ) );
        ActivityCompat.requestPermissions ( activity,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                1);
}


 calling from controller:

boolean isPermissionGiven = StandardMethods.checkPermission ( phoneActivity );
    if ( !isPermissionGiven ) {
       StandardMethods.requestPermission ( phoneActivity );
    }


gives this Error :

E/Utkarsh---: checkPermission: class .PhoneNumberActivity
E/Utkarsh---->>>: requestPermission: class.PhoneNumberActivity
V/FA: Activity resumed, time: 80577484
V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 19
V/FA: Activity paused, time: 80577499
E/Utkarsh---: checkPermission: class.PhoneNumberActivity
V/FA: Activity resumed, time: 80577732

根据日志检查许可和请求许可被称为

1 个答案:

答案 0 :(得分:0)

我要求的许可是:

public static boolean checkPermission ( Context context ) {

if ( hasPermission ( context, Manifest.permission.READ_EXTERNAL_STORAGE ) )
                return true;
else if ( hasPermission ( context, Manifest.permission.WRITE_EXTERNAL_STORAGE ) )
                return true;
else if ( hasPermission ( context, Manifest.permission.READ_SMS ) )
                return true;
else if ( hasPermission ( context, Manifest.permission.SEND_SMS ) )
                return true;
else if ( hasPermission ( context, Manifest.permission.RECEIVE_SMS ) )
                return true;
            return false;

}

private static boolean hasPermission ( Context context, String flag ) {
            return ContextCompat.checkSelfPermission ( context, flag ) != PackageManager.PERMISSION_GRANTED;
        }

“SEND SMS”存在一些问题权限,它总是发送权限未授予我不知道为什么,虽然我不是在我的应用程序发送短信所以我删除它。删除这个使我的错误消失了。在那之前,错误一直无限,我不知道为什么它有所帮助。虽然如果写在活动内部,相同的权限也很有效。现在他们处于非活动类(标准方法)。

请某人提供原因