0

我为 Marshmallow Devices 使用了以下代码。我应该用什么来在牛轧糖中运行我的应用程序?

boolean isMdevice;
boolean pstatus;
String[] perms = {Manifest.permission.ACCESS_NETWORK_STATE,
        Manifest.permission.ACCESS_WIFI_STATE,
        Manifest.permission.INTERNET,
        Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.CALL_PHONE,
        Manifest.permission.READ_CONTACTS,
        Manifest.permission.SEND_SMS,
        Manifest.permission.WRITE_CONTACTS,
        Manifest.permission.READ_PHONE_STATE,
        Manifest.permission.RECEIVE_SMS};

int code = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    isMdevice = isMarshmallowPlusDevice();
    pstatus = isPermissionRequestRequired(One_Activity.this, perms, code);
}

 public static boolean isMarshmallowPlusDevice() {

    return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1;
}

@TargetApi(Build.VERSION_CODES.M)
public static boolean isPermissionRequestRequired(Activity activity, @NonNull String[] permissions, int requestCode) {
    if (isMarshmallowPlusDevice() && permissions.length > 0) {
        List<String> newPermissionList = new ArrayList<>();
        for (String permission : permissions) {
            if (PERMISSION_GRANTED != activity.checkSelfPermission(permission)) {
                newPermissionList.add(permission);
            }
        }
        if (newPermissionList.size() > 0) {
            activity.requestPermissions(newPermissionList.toArray(new String[newPermissionList.size()]), requestCode);
            return true;
        }
    }

    return false;
}

我正在使用最新的 android studio (2.3) 并使用最新的 sdk。在牛轧糖中应用我的应用程序的最佳方法是什么。

4

1 回答 1

0

Marshmallow 和 Nougat 中的权限系统是相同的,所以我认为您不需要更改所示代码中的任何内容。

于 2017-03-15T12:18:33.837 回答