Use case
during a phone call, User opened some apps and the inCall UI goes behind the APP UI.I need to bring it back using adb command
What i did ?
I used below command
adb shell am start --activity-brought-to-front -n com.google.android.dialer/com.android.incallui.InCallActivity
Which resulted in error
Security exception: Permission Denial: starting Intent { flg=0x10400000 cmp=com.
google.android.dialer/com.android.incallui.InCallActivity } from null (pid=12862
, uid=2000) not exported from uid 10102
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10400000
cmp=com.google.android.dialer/com.android.incallui.InCallActivity } from null (
pid=12862, uid=2000) not exported from uid 10102
at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPe
Is there any way to acheive the desired result using adb?
The InCallActivity activity can't be launched from other applications including launching via am start as the android:exported element of InCallActivity is set to false.
android:exported
This element sets whether the activity can be launched by components of other applications - "true" if it can be, and "false" if
not. If "false", the activity can be launched only by components of
the same application or applications with the same user ID.
If you are using intent filters, you should not set this element "false". If you do so, and an app tries to call the activity, system
throws an ActivityNotFoundException. Instead, you should prevent other
apps from calling the activity by not setting intent filters for it.
If you do not have intent filters, the default value for this element is "false". If you set the element "true", the activity is
accessible to any app that knows its exact class name, but does not
resolve when the system tries to match an implicit intent.
This attribute is not the only way to limit an activity's exposure to other applications. You can also use a permission to limit the
external entities that can invoke the activity (see the permission
attribute).
Related
I have an app which has system privileges. My app displays a UI when the device starts after reboot. Issue is, another activity (not part of my app) also launches, therefore backgrounding my activity.
//my activity starts
ActivityManager: START u0 {flg=0x10000000 cmp=com.company.myApp/.activities.MyActivity} from uid 10097 on display 0
..... stuff happening -> UI is being updated
// some other activity starts (automatically)
ActivityManager: START u0 {act=com.company.someOtherApp.Presentation.APL_RenderDocument flg=0x18000000 pkg=com.company.test cmp=com.company.test/.SomeOtherActivity (has extras)} from uid 10082 on display 0
// my activity goes into background.
MyActivity: onPause()
MyActivity: onStop()
Is there a way to prevent this other application from being created (or from being run)?
I'm looking into 2 particular methods
setComponentEnabledSetting()
Set the enabled setting for a package component (activity, receiver, service, provider). This setting will override any enabled state which may have been set by the component in its manifest.
setApplicationEnabledSetting()
Set the enabled setting for an application This setting will override any enabled state which may have been set by the application in its manifest. It also overrides the enabled state set in the manifest for any of the application's components. It does not override any enabled state set by setComponentEnabledSetting(ComponentName, int, int) for any of the application's components.
I don't quite understand the difference of if those methods can do what I want to achieve.
If an "enabled setting"/"enabled state" for a package/application is set to disabled, does that mean that application or package never gets invoked?
Is there another approach?
There are two ways as far I know
One is kill process
Process.killProcess( APP-PROCESS-ID )
Or you can kill background processes with activity manager liek this
ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
am.killBackgroundProcesses(packageName);
Declare this permission KILL_BACKGROUND_PROCESSES
When application is in background and screen is locked,I'm unable to start activity, there is no exception or warning, onCreate() is just not called. I've been struggling against this problem for while, and I think I've finally found the source of it.
There is a line in logs:
D/com.android.server.am.ExtraActivityManagerService: MIUILOG- Permission Denied Activity KeyguardLocked: Intent { flg=0x14010000 cmp=com.trueconf.videochat/com.trueconf.gui.activities.Call (has extras) } pkg : com.trueconf.videochat uid : 10634
Is this why I can't start an activity? Also, how do I solve this, should I disable keyguard or something?
This is a special permission on MIUI that has to be enabled for apps.
You can find it in
Settings
Manage Apps
YOUR APP
Other permissions
Show on Lock screen
User must enable this manually. As far as I know, the best you can do is to guide the user to this settings menu directly by launching an intent (and probably showing some explainer text prior to this).
Intent looks like this
startActivity(new Intent("miui.intent.action.APP_PERM_EDITOR").putExtra("extra_pkgname", getPackageName()))
Make sure to try catch it as it can throw exceptions if activity can't be started (e.g. the device actually is not running MIUI or the intent is somehow not valid on the particular device/version)
I want to launch my customized screen when user dials any number from my android app instead of default caller screen.
Generally speaking, in order to know how to override any default Activity, first you need to know the structure of the Intent that can launch the Activity.
Determining the structure of the Intent
Open Android Monitor (aka Logcat)
Filter the log to only show those matching the string "ActivityManager"
Launch the Activity that you want to override. In your case, launch the call screen
If the Activity can be overridden, you should see a log entry with "START...", copy that entry so that you don't lose it in the log. On my device, this entry was:
START u0 {act=android.intent.action.CALL dat=tel:xxxxxxxxxxx flg=0x10000000 cmp=com.android.server.telecom/.CallActivity (has extras)} from uid 10088 on display 0
This Intent is made up of
act - The Intent action
dat - The Intent data
cmp - The Intent component
Now you need to check if this Intent can launch the default dialer without specifying the component.
Checking if a default Activity can be overridden
adb shell
am start -a android.intent.action.CALL -d tel:xxxxxxxxxxx (fill in the number you want to test with)
If it launches the dialer, then, voila. You should be able to create an IntentFilter for your application, setting the action and the data appropriately. Then, the next time the user tries to make a call, it will ask the user which app they want to use.
In Android API documentation, it says: "To allow other apps to start your activity, you need to add an intent-filter element in your manifest file for the corresponding element."
Does that mean, if I declare an intent-filter for my Activity, say A1, then it opens the door right away and other apps can start A1? If there is no intent-filter declared, then A1 can only be started within the same app. Correct?
Your analysis is correct... for the default behavior.
What really controls whether another app can start your activity is whether or not it is exported. Technically, that is controlled by the android:exported flag on your <activity> element in the manifest.
The default value of android:exported for an <activity> is true if you have an <intent-filter>, false otherwise. Since that is what you want 99.44% of the time, you rarely see an <activity> have an explicit android:exported attribute.
If Activity manager launches the MainActivity through intent-filter with action=main, and category=launcher, then which type of intent is used?
I'm confused little bit. Is it implicit intent?
An intent is an abstract description of an operation to be performed. Its most significant use is in the launching of activities.
when the user clicks on the application icon, the android system looks in the manifest file for the intent with
action="android.intent.action.MAIN"
and
category="android.intent.category.LAUNCHER".
MAIN action is the main entry point of the application.
LAUNCHER category means it should appear in the Launcher as a top-level application.
Intent is just a piece of information about intention. Intent do not starts anything. It just inform OS that there is a need to do something (i.e start app). System looks for apps able to resolve this intention, starts them and pases to them starting intent (becouse you can pass some portion of data in it).
When user clicks app icon in launcher, launcher application generates and sens intent to OS (with explicit name of desired application to start). Android creates separate DVM, main activity class, starts acrivity's life cycle with calling onCreate() and brings activity to foreground.
When the user selects your app icon from the Home screen, the system calls the onCreate() method for the Activity in your app that you've declared to be the "launcher" (or "main") activity. This is the activity that serves as the main entry point to your app's user interface.
You can define which activity to use as the main activity in the Android manifest file, AndroidManifest.xml, which is at the root of your project directory.
The main activity for your app must be declared in the manifest with an intent-filter that includes the MAIN action and LAUNCHER category(That you know probably).
If a component does not have any intent filters, it can receive only explicit intents. A component with filters can receive both explicit and implicit intents.
Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters. Filters with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings are the exception. They mark activities that begin new tasks and that are represented on the launcher screen. They can include "android.intent.category.DEFAULT" in the list of categories, but don't need to.
For more details please refer this link:
http://developer.android.com/guide/components/intents-filters.html