To cut the story short. My logcat says:
java.lang.SecurityException: Permission Denial: starting Intent {
act=android.bluetooth.adapter.action.REQUEST_DISCOVERABLE
cmp=com.android.settings/.bluetooth.RequestPermissionActivity (has
extras) }
While I'm trying to execute:
Intent discoverIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 600);
startActivity(discoverIntent);
I have included all required permissions in the manifest. Moreover, some time ago I have written another application using bluetooth, which includes exactly this code (and I'm using the same there permissions). In that app everything works properly, here I get this exception while executing startingActivity(discoverIntent).
Do you have any ideas what's going on?
ANSWER ANSWER ANSWER
Maybe it sounds silly, but after restarting(sic!) my mobile phone, everything works perfect and I don't get any exceptions. If you have problem like this, try this simple solution.
Related
I want to open settings screen from my app.
I have made app exported = true in Manifest
Besides that I made sure that I pick correct configuration app while running
from this post -> Android - java.lang.SecurityException: Permission Denial: starting Intent
But still got this error
java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.android.settings/.SubSettings } from ProcessRecord{a973751 21451:com.myapp.android.main/u0a157} (pid=21451, uid=10157) not exported from uid 1000
My code of launching the activity is
val intentTwo = Intent()
intentTwo.setClassName("com.android.settings",
"com.android.settings.SubSettings")
startActivity(intentTwo)
I have also tried this one
val intentOne = Intent()
intentOne.setComponent(ComponentName("com.android.settings",
"com.android.settings.SubSettings"))
startActivity(intentOne)
Any ideas on that?
SubSettings is not exported from the Settings app, at least for AOSP and Android 13. For any device configured this way, you cannot start this activity.
Also, please bear in mind that the system Settings app frequently gets modified by device manufacturers. As a result, there is no requirement for any device to even have SubSettings, let alone have it available to be started by external apps.
And, note that SubSettings does not seem to do much.
I'm facing a weird issue trying to provide a file in Android 10. My code works fine in Android 9 and 11 but in Android 10 only works 50% of the times. There are no difference on the system status when it works and when it doesn't.
The intent:
val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(file, UpdateHelper.APK_TYPE)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
If I grant the permission explicitly, it always work. So my question is not how to fix it, but if there are any explanation for it that I'm missing. In my understanding granting the permission in the intent is the preferred way of doing it.
context?.grantUriPermission(packageName, file, Intent.FLAG_GRANT_READ_URI_PERMISSION)
Reviewing the documentation, it seems to be a race condition.
Permissions granted in an Intent remain in effect while the stack of the receiving Activity is active. When the stack finishes, the permissions are automatically removed.
For some reason this does not affect Android 9 and 11. But in Android 10 does.
The reason for my app to be finished is that I'm using this to pass a new apk to the packageInstaller in order to update the app.
Here is my code:-
public void onClick(View v) {
try {
startActivity(new Intent(
"android.intent.action.SHOW_ALARMS"));
} catch (ActivityNotFoundException ignore) {
Toast.makeText(ac, "ActivityNotFoundException",
Toast.LENGTH_LONG).show();
}
}
This works on the Android emulator running Android 12 API 31: it shows the system clock application with the alarms page. On my Samsung Galaxy S21, also running Android 12 API 31, I get this error:-
Process: uk.co.yahoo.p1rpp.secondsclock, PID: 27629
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SHOW_ALARMS cmp=com.sec.android.app.clockpackage/.alarm.activity.AlarmCTSHandleActivity } from ProcessRecord{769a91e 27629:uk.co.yahoo.p1rpp.secondsclock/u0a362} (pid=27629, uid=10362) requires com.android.alarm.permission.SET_ALARM
at android.os.Parcel.createExceptionOrNull(Parcel.java:2437)
at android.os.Parcel.createException(Parcel.java:2421)
at android.os.Parcel.readException(Parcel.java:2404)
at android.os.Parcel.readException(Parcel.java:2346)
at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:2878)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1743)
at android.app.Activity.startActivityForResult(Activity.java:5465)
at android.app.Activity.startActivityForResult(Activity.java:5423)
at android.app.Activity.startActivity(Activity.java:5809)
at android.app.Activity.startActivity(Activity.java:5762)
at uk.co.yahoo.p1rpp.secondsclock.SettingsActivity$25.onClick(SettingsActivity.java:538)
...
Here is the first bit of my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.yahoo.p1rpp.secondsclock">
<uses-permission android:name="android.permission.SET_ALARM" />
...
I'm actually asking for the permission even though I shouldn't need it since I'm asking to look at the alarms, not to set one. Without the permission request in the manifest, it still works on the emulator and fails in the same way on the phone.
I see the same behaviour (on both the emulator and the phone) with both debug and release builds.
In case someone asks why I'm doing this, I've written a home screen seconds clock widget, which will be published on github when I have it fully working. I want clicking on the widget to go to the system's clock app, which doesn't work because of this problem. The code shown is test code to check why the code in the widget fails, because the widget code executes in the context of the home screen launcher and is harder to debug.
I can go to the system clock app by using an Intent with its ComponentName (and this works without an error on the phone), but different Android phone models have different clock apps with different Componentnames, so it will only work on one type of phone. I did have code to search the PackageManager for the ComponentName of a clock, but Google's latest security upgrade in API 31 doesn't allow me to do that any more.
Why is the SecurityException happening and what if anything can I do to prevent it?
Why is the SecurityException happening
Samsung apparently has an android:permission attribute for that <activity> requiring that callers need to hold that permission to be able to start that activity.
what if anything can I do to prevent it?
You cannot prevent it. Samsung requires that permission, either intentionally or due to some screwup. You either need to hold the permission or you need to wrap the startActivity() call in a try/catch and "gracefully degrade" if you get that exception.
It does not required the permission that you have mentioned above rather it requires a different permission.
Replace this
<uses-permission android:name="android.permission.SET_ALARM" />
With
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
I developed an app using Bluetooth in android that works fine, but I encounter some issue when I try it in Android TV.
According to Bluetooth tutorial, I used this to make my device discoverable:
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
It works fine in normal device, but in Android TV, I get an ActivityNotFoundException:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.bluetooth.adapter.action.REQUEST_DISCOVERABLE (has extras) }
If I understand well, this exception means that there isn't an activity by default to ask the request to the user (I think the default dialog to ask the permission).
So is there a way to create our own kind of activity (to handle this behavior) or may be not ask the permission to the user. Or of course, may be my approach is totally wrong.
I don't know if it's useful but I'm developing on the Nvidia SHIELD TV.
This is probably related to an issue in your manifest. You'll need to declare one of the Activities in your app to have the capability to receive an Intent from
act=android.bluetooth.adapter.action.REQUEST_DISCOVERABLE
Check out this this answer for more information about how to declare Activities in your manifest.
There are some problems with the ANDROID 6.0 MARSHMALLOW and bluetooth. I had a similar problem : I could'nt perform a discovery with my app on the Android TV but it worked fine with my phone(and I had no Exeptions). I drop the ANDROID 6.0 MARSHMALLOW and went to the 5.3 and it works after that.
I followed all the guidance found on SO to autostart app at boot time.
In my manifest, I have set the right permission (RECEIVE_BOOT_COMPLETED) and also declared my broadcast receiver: .BootReceiver picking up Android.Intent.Action.BOOT_COMPLETED.
I also launch my service in BootReceiver, this is very straightforward stuff.
The thing is, my app starts at boot time on certain devices (I hope most devices) but not on some of them. I have a Xiaomi phone that gives me the following error at boot time:
"Unable to launch app com..example/10120 for broadcast Intent {act=android.intent.action.BOOT_COMPLETE flg=0x8000010 (has extras) }: process is not permitted to autostart."
I am surprised to see this message, because I can see that the list of permissions includes running at startup.
There must be a way, because Whatsapp for instance is launched at boot time.
Any clue would be highly appreciated.
Same here. I tried to delete the file in the SD card ( but the system direct to internal storage ) by using the permission WRITE_EXTERNAL_STORAGE, and get the similar message from log-cat. Maybe it can be fixed by rooting the xiao-mi mobile, that's what I searched from the Internet.