When Android backgrounds an application it creates a screenshot of the current screen. The screenshot is displayed when you click the Overview button.
Is there a way to prevent this backgrounding screen shot (as if I'd used FLAG_SECURE), but allow the users to take screenshots?
You can configure not to show your activity in recent list. Add following code in manifest :
<activity
.....
android:excludeFromRecents="true"
...../>
Or from java code startActivity with flag:
intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Or,
<activity
.....
android:noHistory="true"
...../>
Try this https://stackoverflow.com/a/49442984/5939067 .
The solution above simply sets the secure flag when your app goes background, and clears it when it resumes(so you can take the screenshot while using the app).
It works perfectly for me. I tested with Samsung Galaxy 9+(Android 9), LG V30(Android 8) and LG G7 ThinQ(Android 8).
Related
If I send files via Intent to other applications, the chooser dialog on Samsung devices shows the package name of my application besides the defined Activity labels. On Nexus devices I only see the labels, as expected. How to fix this issue?
On Galaxy Note 3 both, label and package name are shown (see screenshot)
On Galaxy S3 only the package name is visible
Ok, I got it. It happens only if you use equal labels for your Activities. Some devices show you the package name for better differentiation.
Try setting the application label in AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="#string/my_app_name">
<activity>
...
</activity>
</application>
</manifest>
I have used the following code for enabling Bluetooth (as described here) and the same runs in onCreate() of the launcher activity of my app -
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, 101);
Now the problem is when this dialog is popped up, then every time i rotate the device, the dialog gets created again again on top of the previously created dialog.
I am preventing my activity from getting recreated by handling it from manifest
android:configChanges="orientation|screenSize|keyboardHidden"
This doesn't occur in all devices
I am getting this on :
LG Nexus 5, Samsung Galaxy Grand
And not on :
Samsung I9500 Galaxy S4
Edit :
Found this Reported Issue but couldn't find the solution
Here is the link
Created another issue Here
It seems this bug was never solved !!
I have tested this on several devices including latest Pixel device and it still exists
And the same has been raised several time on code.google.com/p/android
Reference to raised issues :
Issue 60002: Bluetooth permission request dialog
Issue 219105 On each rotation, dialog for requesting user permission to enable Bluetooth, the request dialog is placed on the top of the stack
Issue 24931: Bluetooth permission request dialog - recreated on screen rotation(orientation change)
In case anyone finds a solution then please do post it here
When we rotated device its configration change method is call in activity.
You just need to add android:configChanges="orientation" in your activity element in AndroidManifest.xml
<activity
android:name=".MainActivty"
android:configChanges="orientation"
android:label="#string/app_name"></activity>
I hope it will help you to solve the problem
I have an activity that I want not be seen in the Recents items. I have used the following in my Manifest file :
<activity
android:name=".WidgetLayout"
android:excludeFromRecents="true"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppTheme.Dialog">
It works perfectly well on all android versions but when I try it on Lollipop (SDK 21) it shows up always in the Recent items. So is it an OS bug as stated by many or I have made some error. Is there a solution to the problem if yes then how can I solve it ?
This is a known issue into Android 5.0, since L preview.
Try with android:taskAffinity
android:taskAffinity=".WidgetLayout"
android:excludeFromRecents="true"
You Should try adding android:autoRemoveFromRecents="true"
Hello my question is a bit difficult let me explain and try to understood
I have a custom Home who is set as default when user press home. Know i need a way to ask wich home use when i press on a setting key, or a way to launch Setting activity for delete home default action.
In fact i wan't a way to go back to home app installed by google instead of mine just in case.
I need this because my custom home is still in dev and don't have all feature yet.
I need to keep my home as a default action when user press home buton but i need to add a home selector in special case.
I have try to use finish() when i need to go back to old home but mine as default is automaticly relaunch because he is the default one.
Any idea?
EDIT
I try to reformul a bit.
I'm making a home apps. I set it as default on my tablet. My home apps don't have all feature yet. And when i will launch something or go to setting i need to relaunch default home app.
So i need a way inside my app to reset default home action or launch a home apps, or ask user to choice wich app he will use has home apps.
Hope this is clear for all.
Probably you should use this one to implement your idea. keep the below lines in your manifest file.
<activity android:name="Home"
android:theme="#style/Theme"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
For more info about the sample project. just go the below path in your Android SDK
\android-sdk\samples\android-8\Home
EDIT :
Hi Please check this to pro grammatically unset the default application.
How do I use PackageManager.addPreferredActivity()?
for more info go through this also to clear the clearPackagePreferredActivities
http://developer.android.com/reference/android/content/pm/PackageManager.html#clearPackagePreferredActivities%28java.lang.String%29
hope this helps you.
I have been working on a replacement for the stock Car Home app for a bit, and I am completely stumped on how to override the Home button so that my app will be brought back to the foreground whenever the phone is docked. This is the way that Car Home works, so there must be a way.
It seems that BroadcastReceivers won't work, because the intent that is broadcast whenever the Home button is pressed will still cause the default homescreen app to launch; I cannot prevent it. I can override the Home button from within my app, but that does me no good since this needs to work when the user is outside my app. Car Home also does not do anything weird like set itself as the default homescreen app while it's running (I checked the logcat to make sure).
What can I try next?
Well, after many months I have finally found the answer to this question. The key is the "android.dock_home" metadata element, found here:
http://developer.android.com/reference/android/content/Intent.html#METADATA_DOCK_HOME
By using this in your AndroidManifest.xml, you can make your dock application become the home application temporarily. To do this, add this line to the AndroidManifest.xml inside the Activity tags for the dock app activity:
<meta-data android:name="android.dock_home" android:value="true" />
If the value is set to true, as long as your phone is docked the Home button will return you to the dock app. After undocking, the Home button will take you back to your normal home app.
Unfortunately, there is no way in the public APIs to override the Home button without the user confirming it.
Your best bet would be to implement a CATEGORY_HOME Intent. This means when a user pressed Home they would be presented with the option to run the standard Home or yours and make yours the default if they wanted.
When your application was launched you could then check if the phone was docked. If the phone is not docked you could then open the standard Home screen and close your app before anything is displayed.
You need to the correct intent filter in your manifest for the app to launch automatically when you dock the phone. Refer to http://developer.android.com/reference/android/content/Intent.html#CATEGORY_CAR_DOCK for the information.
I found a way to tackle HOME key. For your application set the manifest as
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
Now your application is an alternate Launcher application.
Use the adb, and disable the launcher application using package manager
pm disable com.android.launcher2.
Now the Home key press will aways stay in the same screen.