2016-08-16 5 views
0
public void checkPermissions() { 

    Log.i(TAG, " Checking permissions."); 

    // Verify that all required contact permissions have been granted. 
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { 

     // Contacts permissions have not been granted. 
     Log.i(TAG, "Call Phone permissions has NOT been granted. Requesting permissions."); 
     requestPermissions(); 

    } else { 

     // Contact permissions have been granted. Show the contacts fragment. 
     Log.i(TAG, 
       "Contact permissions have already been granted"); 
     showContactDetails(); 
    } 
} 


public void customDialog(Context ctx) { 

    AlertDialog.Builder builder; 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     builder = new AlertDialog.Builder(ctx, android.R.style.Theme_Material_Light_Dialog_Alert); 
     builder.setMessage("Call permissions are needed to demonstrate access").setNeutralButton("Ok", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, 
             int whichButton) { 
         ActivityCompat.requestPermissions(CallChoosyActivity.this, Permissions, REQUEST_CALL_PHONE); 
        } 
       }); 

     AlertDialog alertDialog = builder.create(); 
     alertDialog.show(); 
    } else { 
     builder = new AlertDialog.Builder(ctx); 
     builder.setMessage("Call permissions are needed to demonstrate access").setNeutralButton("Ok", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, 
             int whichButton) { 

        } 
       }); 
     AlertDialog alertDialog = builder.create(); 
     alertDialog.show(); 
    } 

} 

public void requestPermissions() { 

    // BEGIN_INCLUDE(contacts_permission_request) 
    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) { 

     // Provide an additional rationale to the user if the permission was not granted 
     // and the user would benefit from additional context for the use of the permission. 
     // For example, if the request has been denied previously. 
     Log.i(TAG, "Displaying call permission rationale to provide additional context."); 

     customDialog(CallChoosyActivity.this); 
    } else { 
     // Contact permissions have not been granted yet. Request them directly. 
     ActivityCompat.requestPermissions(this, Permissions, REQUEST_CALL_PHONE); 
    } 
    // END_INCLUDE(contacts_permission_request) 
} 


@Override 
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, 
             @NonNull int[] grantResults) { 

    if (requestCode == REQUEST_CALL_PHONE) { 
     Log.i(TAG, "Received response for contact permissions request."); 

     // We have requested multiple permissions for contacts, so all of them need to be 
     // checked. 
     if (PermissionUtil.verifyPermissions(grantResults)) { 
      // All required permissions have been granted, display contacts fragment. 
      showContactDetails(); 
     } else { 
      Log.i(TAG, "Contacts permissions were NOT granted."); 
     } 

    } else { 
     super.onRequestPermissionsResult(requestCode, permissions, grantResults); 
    } 
} 

public void showContactDetails() { 
    Intent callIntent = new Intent(Intent.ACTION_CALL); 
    callIntent.setData(Uri.parse("tel:" + PartyTabsActivity.numbersList.get(0))); 
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { 

     return; 
    } 
    startActivity(callIntent); 
} 

にコール許可をチェックしていますそのlogcatでこれを示す私はマシュマロ

java.lang.SecurityException:許可拒否:開始意図は{= android.intent.action.CALL DAT働きます= tel:xxxxxxxxxx cmp = android/com.android.internal.app.ResolverActivity}無効なアクセス権を持つProcessRecord {2dd511f 24656:com.marg.pharmanxt/u0a158}(pid = 24656、uid = 10158)の android.permission.CALL_PHONE android.os.Parcel.readException(Parcel.java:1599)の android.os.Parcel.readException(Parcel.java:1552)の android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2771)

+0

をチェックしているされているよう

int checkPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE); if (checkPermission != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( this, new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL_PHONE); } else { customDialog(CallChoosyActivity.this); } 

はあなたonRequestPermissionsResultを残しますか? –

+0

私はMarshMallowをチェックしています –

答えて

2

これに基づいて許可要求コードを変更してください。それはあなたがロリポップやマシュマロデバイスに

関連する問題