I get a crash at a user when calling requestPermissions on a samsung S5. I don't understand what could be the reason?
if (Build.VERSION.SDK_INT >= M) {
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
MainActivity.this.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 100);
Here is the stack crash:
Caused by: android.content.ActivityNotFoundException:
at android.app.Instrumentation.checkStartActivityResult (Instrumentation.java:1878)
at android.app.Instrumentation.execStartActivity (Instrumentation.java:1673)
at android.app.Activity.startActivityForResult (Activity.java:4915)
at android.app.Activity.requestPermissions (Activity.java:4167)
at com.narb.checknetwork.MainActivity.permissionRequest (MainActivity.java:276)
at com.bernard_zelmans.checknetwork.MainActivity.onCreate (MainActivity.java:101)
Added information.
I have all the permissions I require included.
Here is my manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.narb.checknetwork">
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:allowBackup="true"
android:configChanges="keyboardHidden|screenSize"
android:label="CheckNet"
android:largeHeap="true"
android:logo="@drawable/networksafe"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
used below code
if (Build.VERSION.SDK_INT >= M) {
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
this.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 100);
}
Try like below...
if (Build.VERSION.SDK_INT >= M) {
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 100);
One more important thing, Check whether you declared MainActivity in your Manifest.xml or not
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.