Reputation: 247
I need use ActivityCompat.requestPermissions();
but with the message : can not resolve .requestPermissions
. my compileSdkVersion
is 26.
What can I do to solve this problem?
this is my code :
private int MY_PERMISSIONS_REQUEST_SMS_RECEIVE = 10;
ActivityCompat.requestPermissions(this,new String[]{
Manifest.permission.RECEIVE_SMS}
, MY_PERMISSIONS_REQUEST_SMS_RECEIVE);
Upvotes: -1
Views: 2633
Reputation: 59004
If you put ActivityCompat.requestPermissions()
outside any method you will get can not resolve .requestPermissions
error.
Just put ActivityCompat.requestPermissions()
inside onCreate or some other method. Like this.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions()...
}
You should follow good tutorials and read them carefully, coding is not just copy and paste in your IDE.
Upvotes: 1
Reputation: 1637
i think you must use from below code
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
and use
compile 'com.android.support:appcompat-v7:+'
Upvotes: 2