Android Question How to run any intent / activity?

plager

Member
Hello community,
I'd like to ask a general question:
how to run ANY intent / package / activity?
A bit of theory:
Usually every app has some (or more) activity. I'd like to run any activity of any app / package. But this is not that mandatory. What I really like to achieve is to run ANY settings intent / activity.

I have an app (which is not on google play store anymore), which shows an current activity running. During the time I managed some settings to run:

This gives an intent about battery optimization:
Dim poInt As Intent
poInt.Initialize("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS","")
StartActivity(poInt)

This gives an intent about mobile data usage:
Dim poInt As Intent
poInt.Initialize("android.settings.DATA_USAGE_SETTINGS","")
StartActivity(poInt)

This throws an activity about casting:
Dim poInt As Intent
poInt.Initialize("android.settings.CAST_SETTINGS","")
StartActivity(poInt)

... and a few more...



However, some are a bit strange to me (it's because I don't have a fully knowledge about this)
This calling:
Dim poInt As Intent
poInt .Initialize("android.intent.action.POWER_USAGE_SUMMARY","")
StartActivity(poInt )

gives this (according to 'Current activity' app display):
com.samsung.android.lool
com.samsung.android.sm.battery.ui.graph.Last7DaysGraphActivity



Please, take a look on attached screenshots. They are made with launched app mentioned before called 'Current activity'
These shots shows some intents and also a note from 'Current activity' app displayed at very top of screenshot.

What I really want to achieve is to run 'Charging settings', as displayed on one of the screenshots. I'd like to launch it directly, not within about five click through settings or so...
Also, having a list of recents as displayed of one of the screenshots would be also nice - with launch desired intent.

Anyone can help with this?
Many thanks.
 

Attachments

  • shot_battery.jpg
    shot_battery.jpg
    279.2 KB · Views: 34
  • shot_chargsett.jpg
    shot_chargsett.jpg
    213.6 KB · Views: 32
  • shot_recents.jpg
    shot_recents.jpg
    503.4 KB · Views: 32

plager

Member
Thank you, Erel, for the answer. Sorry about not putting code in code tags, will do better this time.

I understand android:exported=True. However, as I wrote, I struggle to get a correct intent / activity, even with help of mentioned app 'current activity'. For example, if you take a look at a 'shot_battery', you can see a bettery intent with activities displayed at the top. I tried this:

B4X:
Dim in As Intent
Dim pm As PackageManager
in = pm.GetApplicationIntent("com.samsung.android.lool")
'in.SetComponent("com.samsung.android.lool/.com.samsung.android.sm.battery.ui.BatteryActivity")        --> this gives error
'in.SetComponent("/com.samsung.android.sm.battery.ui.BatteryActivity")                                 --> this gives same error
StartActivity(in)
Given error:
B4X:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samsung.android.lool/com.samsung.android.lool.com.samsung.android.sm.battery.ui.BatteryActivity};

Basically, I am able to get to 'Device care' intent (shot 'device_care' from first post) with this line:
B4X:
in = pm.GetApplicationIntent("com.samsung.android.lool")

Not any further, except:
B4X:
poInt .Initialize("android.intent.action.POWER_USAGE_SUMMARY","")
which takes me to Device care.

When I tried it to use it like this:
B4X:
Dim intent1 As Intent
intent1.Initialize("com.samsung.android.lool","com.samsung.android.sm.battery.ui.BatteryActivity")
StartActivity(intent1)

it gives this error:
B4X:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.samsung.android.lool dat= flg=0x20000 }

As I wrote in initial post, this:
B4X:
Dim poInt As Intent
poInt .Initialize("android.intent.action.POWER_USAGE_SUMMARY","")
StartActivity(poInt )

gives this (according to 'Current activity' app display):
B4X:
com.samsung.android.lool
com.samsung.android.sm.battery.ui.graph.Last7DaysGraphActivity
(screenshot 'battery_activity' in this post.)
Why is that? How does it work?

I know that is possible somehow, tried a few apps to make a shortuts to intents and / or activities. One of those took me directly in charge settings displayed in 'shot_chargesett' in first post. Unfortunatelly, I have no clue how to achieve this :(
Also, calling recent apps from the screenshot 'shot_recents' from the first post is possible programmatically. Some of apps know how to do that. But how?
 

Attachments

  • shot_battery_activity.jpg
    shot_battery_activity.jpg
    265.1 KB · Views: 15
Upvote 0
Top