2017-02-23 17 views
2

最近、アンドロイドのヌガーと一緒にSamsungの携帯電話で私のアプリを実行中にクラッシュしています。 com.sec.android.provider.badge.BadgeProviderの実行時アクセス許可を与えなかったため、クラッシュしました。誰かが私を助けてくれたら、私はこのバッジプロバイダのランタイム許可を与える方法を知らない。許可の否認:書き込みcom.sec.android.provider.badge.BadgeProvider

クラッシュレポートが

java.lang.SecurityExceptionの下に示します:権限の拒否:書き込みcom.sec.android.provider.badge.BadgeProvider URIコンテンツ:PID = 5325から//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)

答えて

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); 
    } 
} 

} 
+0

いいえ、実行時にバッジのアクセス許可を実装する方法 –

+0

Emm、コードはすべてあなたのために行います。不要なManifest.permission.xxxxを削除し、 'com.sec.android.provider.badge.permission.WRITE'と置き換える必要があります。 –

+0

しかし、これを試してみると、.secのエラーは.secで表示されませんシンボルを解決する –

関連する問題