2017-04-26 12 views
6

मैं समूह में एकाधिक Run time permission on android 6.0 के लिए पूछने के लिए कोड लिख रहा हूं। सब ठीक है मैं इसके लिए कुछ अच्छे उदाहरण का पालन करता हूं लेकिन अभी भी समस्या है।एकाधिक रन टाइम अनुमति दें

ActivityCompat.shouldShowRequestPermissionRationale (context, READ_PHONE_STATE) में संदर्भ कि गलत पहला तर्क संदर्भ पर इसके देने त्रुटि। कृपया इसे हल करने में सहायता करें।

अग्रिम धन्यवाद

कोड है:

if (ContextCompat 
        .checkSelfPermission(SpalshActivity.this, 
          READ_PHONE_STATE)+ContextCompat.checkSelfPermission(context, 
        WRITE_EXTERNAL_STORAGE) +ContextCompat.checkSelfPermission(context, 
        CAMERA) + ContextCompat 
        .checkSelfPermission(context, 
          READ_CONTACTS)+ContextCompat 
        .checkSelfPermission(context, 
          CALL_PHONE)+ContextCompat 
        .checkSelfPermission(context, 
          ACCESS_FINE_LOCATION)+ContextCompat 
        .checkSelfPermission(context, 
          READ_SMS)== PackageManager.PERMISSION_GRANTED) { 
       myMethod(); 

      } 
       else { 
       if (ActivityCompat.shouldShowRequestPermissionRationale 
         (context, READ_PHONE_STATE) ||ActivityCompat.shouldShowRequestPermissionRationale 
         (context, WRITE_EXTERNAL_STORAGE)|| 
         ActivityCompat.shouldShowRequestPermissionRationale 
           (context, CAMERA) || 
         ActivityCompat.shouldShowRequestPermissionRationale 
           (context, READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale 
         (context, CALL_PHONE) || ActivityCompat.shouldShowRequestPermissionRationale 
         (context, ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale 
         (context, READ_SMS)) { 
        Snackbar.make(findViewById(android.R.id.content), 
          "Please Grant Permissions", 
          Snackbar.LENGTH_INDEFINITE).setAction("ENABLE", 
          new View.OnClickListener() { 
           @Override 
           public void onClick(View v) { 
            ActivityCompat.requestPermissions(SpalshActivity.this, 
              new String[]{READ_PHONE_STATE,WRITE_EXTERNAL_STORAGE,CAMERA, READ_CONTACTS, CALL_PHONE, ACCESS_FINE_LOCATION, READ_SMS}, 
              REQUEST_READ_PHONE_STATE); 
           } 
          }).show(); 
       } else { 
        ActivityCompat.requestPermissions(SpalshActivity.this, 
          new String[]{READ_PHONE_STATE,WRITE_EXTERNAL_STORAGE,CAMERA, READ_CONTACTS, CALL_PHONE, ACCESS_FINE_LOCATION, READ_SMS}, 
          REQUEST_READ_PHONE_STATE); 
       } 
      } 
      } 

    } 
+1

अपनी सक्रियता का प्रयास करें। संदर्भ के बजाय, इसकी कोशिश करें। –

उत्तर

6

पहले पैरामीटर है android.app.Activity प्रकार, आप context इस जगह से पारित नहीं कर सकते हैं ताकि this बजाय नीचे दिए गए कोड की तरह context का उपयोग करें: -

if (ActivityCompat.shouldShowRequestPermissionRationale 
         (this, READ_PHONE_STATE) ||ActivityCompat.shouldShowRequestPermissionRationale 
         (this, WRITE_EXTERNAL_STORAGE)|| 
         ActivityCompat.shouldShowRequestPermissionRationale 
           (this, CAMERA) || 
         ActivityCompat.shouldShowRequestPermissionRationale 
           (this, READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale 
         (this, CALL_PHONE) || ActivityCompat.shouldShowRequestPermissionRationale 
         (this, ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale 
         (this, READ_SMS)) 
0

को बदलने का प्रयास करें 10 this

if (ActivityCompat.shouldShowRequestPermissionRationale(this, READ_PHONE_STATE) || 
    ActivityCompat.shouldShowRequestPermissionRationale(this, WRITE_EXTERNAL_STORAGE) || 
    ActivityCompat.shouldShowRequestPermissionRationale(this, CAMERA) || 
    ActivityCompat.shouldShowRequestPermissionRationale(this, READ_CONTACTS) || 
    ActivityCompat.shouldShowRequestPermissionRationale(this, CALL_PHONE) || 
    ActivityCompat.shouldShowRequestPermissionRationale(this, ACCESS_FINE_LOCATION) || 
    ActivityCompat.shouldShowRequestPermissionRationale(this, READ_SMS)) { 
    //... 
}