权限拒绝:编写com.sec.android.provider.badge.BadgeProvider

时间:2017-02-23 03:10:52

标签: android

我最近在使用Android Nougat在三星手机上运行我的应用程序时遇到了崩溃。我没有给com.sec.android.provider.badge.BadgeProvider授予运行时权限,这使得崩溃。我不知道如何为这个徽章提供者提供运行时权限,如果有人知道请帮助我。

崩溃报告在下面提供

java.lang.SecurityException:Permission Denial:从pid = 5325编写com.sec.android.provider.badge.BadgeProvider uri内容://com.sec.badge/apps,uid = 10242需要com.sec.android .provider.badge.permission.WRITE或grantUriPermission()         在android.os.Parcel.readException(Parcel.java:1693)         在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)         在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)         在android.content.ContentProviderProxy.delete(ContentProviderNative.java:544)

2 个答案:

答案 0 :(得分:0)

这是我用来在运行时请求多个权限的模板。您需要根据自己的需要自行修改

您还需要在清单中加入<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/><uses-permission android:name="com.sec.android.provider.badge.permission.WRITE"/>

public class SplashScreen extends AppCompatActivity {

private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
private static final  int REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS = 124;

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

    setContentView(R.layout.activity_splash_screen);

}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (hasFocus) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}

private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i("Google Play", "This device is not supported.");
        }
        return false;
    }
    return true;
}

@Override
protected void onResume() {
    super.onResume();
     if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
          // Marshmallow+
          askMultipleRuntimePermission();
     }else{
          //below Marshmallow
          //do something
     }
}

@TargetApi(Build.VERSION_CODES.M)
public void askMultipleRuntimePermission(){
    List<String> permissionsNeeded = new ArrayList<String>();

    final List<String> permissionsList = new ArrayList<String>();
    if (!addPermission(permissionsList, Manifest.permission.ACCESS_FINE_LOCATION))
        permissionsNeeded.add("GPS");
    if (!addPermission(permissionsList, Manifest.permission.CAMERA))
        permissionsNeeded.add("Camera");
    if (!addPermission(permissionsList, Manifest.permission.CALL_PHONE))
        permissionsNeeded.add("Phone Call");
    if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE))
        permissionsNeeded.add("Write File");
    if (!addPermission(permissionsList, Manifest.permission.READ_CONTACTS))
        permissionsNeeded.add("Read Contacts");
    if (!addPermission(permissionsList, Manifest.permission.RECORD_AUDIO))
        permissionsNeeded.add("Record Audio");


    if (permissionsList.size() > 0) {
        if (permissionsNeeded.size() > 0) {
            requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
                    REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
            return;
        }
        requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
                REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
        return;
    }
    else{
        //Do something here
    }

}


@TargetApi(Build.VERSION_CODES.M)
private boolean addPermission(List<String> permissionsList, String permission) {
    if (ActivityCompat.checkSelfPermission(this,permission) != PackageManager.PERMISSION_GRANTED) {
        permissionsList.add(permission);
        // Check for Rationale Option
        if (!shouldShowRequestPermissionRationale(permission))
            return false;
    }
    return true;
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS: {
            Map<String, Integer> perms = new HashMap<String, Integer>();
            // Initial
            perms.put(Manifest.permission.ACCESS_FINE_LOCATION, PackageManager.PERMISSION_GRANTED);
            perms.put(Manifest.permission.CAMERA, PackageManager.PERMISSION_GRANTED);
            perms.put(Manifest.permission.CALL_PHONE, PackageManager.PERMISSION_GRANTED);
            perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
            perms.put(Manifest.permission.READ_CONTACTS, PackageManager.PERMISSION_GRANTED);
            perms.put(Manifest.permission.RECORD_AUDIO, PackageManager.PERMISSION_GRANTED);
            // Fill with results
            for (int i = 0; i < permissions.length; i++)
                perms.put(permissions[i], grantResults[i]);
            // Check for ACCESS_FINE_LOCATION
            if (perms.get(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                    && perms.get(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
                    && perms.get(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED
                    && perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
                    && perms.get(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
                    && perms.get(Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) {
                // All Permissions Granted
                // Do something next
            } else {
                // Permission Denied
                Log.i("Permission", " some of the permission have been denied");
                // Alert user about permission denied, and do something
            }
        }
        break;
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

}

答案 1 :(得分:0)

也将其添加到清单文件中。我在三星SM-J250F中发现了类似的问题

    <uses-permission android:name="com.sec.android.provider.badge.permission.READ"/>

具有写许可权