-3

im giving reference of current activity using this pointer in checkSelfPermission method but this is showing following error

'checkSelfPermission(android.content.Context, java.lang.String)' in 'android.support.v4.content.ContextCompat' cannot be applied to '(anonymous android.view.View.OnClickListener, java.lang.String)'

following is code lines

 if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS)){

            }
Ayeshay
  • 1
  • 4

2 Answers2

0

Try this code

if (ContextCompat.checkSelfPermission(YourActivityName.this, Manifest.permission.SEND_SMS)){

            } 
Vinod Pattanshetti
  • 2,465
  • 3
  • 22
  • 36
  • it did not work.... showing error that MainActivity.this is of int type instead of boolean. – Ayeshay Apr 10 '17 at 09:46
  • if (ContextCompat.checkSelfPermission(MainActivity.this , Manifest.permission.SEND_SMS)) !=PackageManager.PERMISSION_GRANTED){ } – Ayeshay Apr 10 '17 at 09:52
0

You are taking the reference of the onclick... use

if (ContextCompat.checkSelfPermission(ActivityName.this, Manifest.permission.SEND_SMS)){

            }
bhaskar kurzekar
  • 238
  • 2
  • 14
  • this is also not working and showing following error Incompatible types. Found: 'int', required: 'boolean' – Ayeshay Apr 10 '17 at 08:54
  • public void onClick(View v) { String message = textmessage.getText().toString(); String telno = texttelno.getText().toString(); if (ContextCompat.checkSelfPermission(MainActivity.this , Manifest.permission.SEND_SMS)){ } } – Ayeshay Apr 10 '17 at 09:14
  • use this >> if(ContextCompat.checkSelfPermission(MainActivity.this , Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED){} – bhaskar kurzekar Apr 10 '17 at 09:24
  • i know i have to complete it yet but what should i do for above error – Ayeshay Apr 10 '17 at 09:30