4
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Intent i = new Intent(Settings.ACTION_APPLICATION_SETTINGS, Uri.parse("package:" + getPackageName())); finish(); startActivity(i); return; } 

I try to check for sdk version marshmello above, but everytime i tried to run it, always cause error like this

12-26 08:21:16.982 6330-6330/com.example.asus.retrofittest3 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.asus.retrofittest3, PID: 6330 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asus.retrofittest3/com.example.asus.retrofittest3.HomeActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.APPLICATION_SETTINGS dat=package:com.example.asus.retrofittest3 } at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2706) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1514) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:163) at android.app.ActivityThread.main(ActivityThread.java:6205) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.APPLICATION_SETTINGS dat=package:com.example.asus.retrofittest3 } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1816) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525) at android.app.Activity.startActivityForResult(Activity.java:4402) at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67) at android.app.Activity.startActivityForResult(Activity.java:4360) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720) at android.app.Activity.startActivity(Activity.java:4699) at android.app.Activity.startActivity(Activity.java:4667) at com.example.asus.retrofittest3.HomeActivity.onCreate(HomeActivity.java:49) at android.app.Activity.performCreate(Activity.java:6864) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)  at android.app.ActivityThread.-wrap12(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1514)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:163)  at android.app.ActivityThread.main(ActivityThread.java:6205)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)  

Not really sure where it went wrong, already tried some suggestion from stackoverflow but it still didnt solve it

3 Answers 3

8

Your setting action here: ACTION_APPLICATION_SETTINGS (Activity Action: Show settings to allow configuration of application-related settings.) that you don't have permission. Please change it into ACTION_APPLICATION_DETAILS_SETTINGS (Activity Action: Show screen of details about a particular application.).

from:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Intent i = new Intent(Settings.ACTION_APPLICATION_SETTINGS, Uri.parse("package:" + getPackageName())); finish(); startActivity(i); return; } 

to:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Intent i = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + getPackageName())); finish(); startActivity(i); return; } 
Sign up to request clarification or add additional context in comments.

Comments

2

Hmm, maybe try like this?

 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null)); 

Comments

0

here works like this

 fun Activity.appSettings(): Intent { return Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).also { val uri = Uri.parse("package:$packageName") it.flags = Intent.FLAG_ACTIVITY_NEW_TASK it.data = uri } } 

then call it from any where through the context

 val localContext = LocalContext.current as ComponentActivity localContext.appSettings().apply { localContext.startActivity(this) } 

As an extended function it worked perfectly

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.