Sidebar
In order to access the sidebar, the user has the press the long back button.
I was wondering if there are anyways to prevent the user from accessing the Sidebar?
Thanks in advance.
The special behaviour of the back button is a Samsung OS specific, meaning they added it to their flavour of Android.
Thus, i fail to see how you can disable it from user code.
One option (although it would be a bit obtrusive) is to disable the back action completely by overriding and see if it stops Samsungs OS from picking up on the button (probably not as it would be OS level call).
This could be done like this:
#Override
public void onBackPressed() {
}
Remember, like i said, this is a bit intrusive, as you alter the behaviour of a common usage method. And it is also not guaranteed to stop Samsung devices to bring up the menu, as that is likely a call on OS not user-level.
Related
I would like to take a photo with MediaStore.ACTION_IMAGE_CAPTURE intent, but disable the settings button in the top-left corner. I was able to find a EXTRA_SHOW_ACTION_ICONS parameter, but it is not well documented. This is the description:
The name of an Intent-extra used to control the UI of a ViewImage. This is a boolean property that specifies whether or not to show action icons.
Even if I set it true or false, nothing changes. What does this parameter do? I use it like this:
takePictureIntent.putExtra(MediaStore.EXTRA_SHOW_ACTION_ICONS, false);
I would like to take a photo with MediaStore.ACTION_IMAGE_CAPTURE intent, but disable the settings button in the top-left corner
As I have pointed out previously, you do not have control over the UI of a third-party camera apps. There are hundreds of such apps; none have to give you any ability to control their UI.
What does this parameter do?
Based on a search of the Android source code, it does nothing in Android itself. If the device happens to have the AOSP Gallery app installed, it appears to control something in the image viewer there. It is certainly possible that some non-AOSP apps use that extra for some particular reason, but that behavior would vary by app.
I'm developing a scientific app in Android Studio. It works smoothy.
The set of source code files is not small, but, as I don't have practically user interface, there is only one activity and there is no intent.
All initialization code is inside OnCreate. Most of times, my app preserves all data, when he gets out of the foreground.
However, maybe (I cannot find a pattern of this event) he loses all data and restart (shows a white screen for 2 / 3 seconds), even if the cell phone don't enter in lock screen and there are just 2 apps running.
There are situations that I comute for another app (like WhatsApp) and resumes for my app, and my data was gone. The app restart again.
There is no error message, no logcat. Nothing.
Mostly, when I lock the screen and enter again, all my app data is there.
PS: My orientation is locked.
PS 2: I've read all related question and there is no hint for me. Based in one answer, I've tried to put in onCreate the following code.
if (!isTaskRoot() {
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null
&& getIntent().getAction().equals(Intent.ACTION_MAIN)) {
finish();
return;
}
No changes for me.
Update:
I've stumbled in solution. it can be read in my own answer. it's related to undesired back button effect for one-activity-app (read here and here ).
For me, as my application has only one activity, back needs to be like a home button: exit the app but preserve all activity data. My app has a real exit button, where the user shows that really wants to do this.
It's my first app that I developing in mobile world and, for extension, Android world
Some problems seems to me like that it is only possible find the solution if one has a hint about its solution. it's a contradiction. One doesn't know but has to know to solve that don't know!
And, in this situation, it's not the case. No hints. Just question marks.
Before, I had not noticed any pattern. People sometimes act so automatically ... However, suddenly the penny dropped.
I've stumbled in solution. Fortunately!
Not in a million years could I suppose that if someone has an activity and presses Back button, (right button in the bottom), you practically quit the application, even if it remains as a running app for the left button in the bottom (app switcher button)
When I've noticed it, I start to research with another focus. And I've discovered two sources: Disable back button in android and Android - Simulate Home click
So the solution is simply to make the Back button act like the Home button (middle button in the bottom). Return to the home screen without losing application data.
And this is done simply by putting in the onCreate, for my only activity, the following code.
override fun onBackPressed() {
val i = Intent(Intent.ACTION_MAIN)
i.addCategory(Intent.CATEGORY_HOME)
startActivity(i)
}
The app I'm currently building has the requirement that the app has to prevent the OS to take a screenshot of the app when it's being pushed into the background for security reasons. This way it won't be able to see the last active screen when switching between apps.
I'm planning to put this functionality in the application class's onPause method, but first I need to find out how I can achieve this functionality.
So is there anybody out there, that has a clue how to fix this?
Try FLAG_SECURE:
public class FlagSecureTestActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.main);
}
}
This definitely secures against manual screenshots and automatic screenshots from the ICS recent-tasks history. It also secures against screen recording (e.g., apps using the media projection APIs).
UPDATE: it also secures against Now On Tap or other assistants on Android 6.0; they will not get access to the details of widgets and containers in your UI if the user brings up the assistant.
UPDATE #2: however, not everything in the activity will be protected. Any pop-up windows — Dialog, Spinner, AutoCompleteTextView, action bar overflow, etc. — will be insecure. You can fix the Dialog problem by calling getWindow() on it and setting FLAG_SECURE. The rest... gets tricky. See this blog post for more.
Be careful about using WindowManager.LayoutParams.FLAG_SECURE, on some devices (verified on Samsung Galaxy ACE, e.g. GT-S5830) this will make the view scrambled. Looks like a Samsung specific bug. I recommend the following:
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
This is what a scrambled screen looks like:
This is working properly on ICS Samsung phones though, so I'm assuming problem is isolated to Gingerbread devices (or older).
The solution provided by CommonsWare continues to be valid also in Lollipop.
Just a note, if you want to continue to not see snapshots in recent list for the entire app, ALL the implemented activities should specify in the onCreate() method the flag getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
before setContentView();
Otherwise a snapshot in the recent list will show the first activity without the flag if the user navigated through it.
In case if someone is looking for a solution in which the app must secure (screen overlay) when the app is background or stick of all running app and the in-app app should allow screenshot.
Try Below:-
#Override
protected void onResume() {
super.onResume();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
#Override
protected void onPause() {
super.onPause();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
Here is a solution for hiding content of an app by covering it with a splash screen when the app is put into the background. This is not using the FLAG_SECURE technique, I simply override the onPause and onResume methods of the screens and modify the view to show one that covers everything in the back.
https://stackoverflow.com/a/52976001/6686912
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
this worked for me, it prevents from taking screenshot and also any inbuilt or third party recording application from recording screen.
This is work for me after adding these line into the onCreate before setContentView of every activity.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
setContentView(R.layout.activity_notification);
As of Android 13, there is a new way to prevent a screenshot being taken for the recent apps list, while still allowing the user to take screenshots while using the app: https://developer.android.com/reference/android/app/Activity#setRecentsScreenshotEnabled(boolean)
I've spent a few hours looking for this. My test device is a nexus 6, though it has been tried on android 4.4 and 5.0+ as well.
Basically I want to catch a user's click of the onBackPress, but I want to do this outside of the activity. Say I've got an object that is initialized and while its running, It is to handle onBackPress, until the its killed.
I've looked into setting an onKeyListener to the contentView but that does not work at all (I figured as much, but its worth a shot).
Any idea how to do this (again, outside the scope of overriding in the activity)?
I cannot imagine something like that being possible since it would be a rather large security risk if a regular application could just catch user input outside of its scope.
The only hardware button I know of that you can detect being pressed even when your activity is not running in the foreground is the camera button, since pressing that generates an Intent. http://developer.android.com/reference/android/content/Intent.html#ACTION_CAMERA_BUTTON
I'm trying to make an application where the user can override the default behaviour of the volume up/down buttons (as well as the screen on/off button - is this possible?). Anyways, using some code along the lines of the following I can do this:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyUp(keyCode, event);
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
//this is where I can do my stuff
return true; //because I handled the event
}
return false; //otherwise the system can handle it
}
But I would like it to be possible even when the application is not open, hence why I'd like to set up a broadcast receiver or maybe stick something in a service to make this possible.
Thanks for any help.
as well as the screen on/off button - is this possible?
Fortunately, no.
But I would like it to be possible even when the application is not open, hence why I'd like to set up a broadcast receiver or maybe stick something in a service to make this possible.
This is not possible for the volume buttons.
For example, AndroSS allows you to override the camera hardware button to take a screenshot.
That is the camera button. If the foreground activity does not consume a camera button click, that gets turned into a broadcast Intent, which other applications can listen for. This behavior is unique to the camera and media buttons and is not used with any other hardware buttons.
this isn't a very good idea. this means every time you press the volume up/down keys you're going to capture it regardless of where you are. what if i want to change my ringer volume? media volume? app that uses the rockers for other uses? it just won't work well and just aggravate people. plus, i'm not sure if its doable.
This is not (easily) possible, because the "onKeyDown" method is overriding Activity.onKeyDown(). For this reason, you have to have a foreground activity to receive these function calls.
I don't have any experience doing this, but you would have to dig a bit deeper into writing your own hardware key intercept/handler functions, since you wouldn't be able to access the one from the activity class.
This probably won't do what you want, but if you make an IME, the IME can capture the volume +/- buttons, and do whatever it wants, like remap to other button presses. For instance, I have modified a Gingerbread-style IME to turn volume +/- buttons to do page up/down in the Kindle and Overdrive apps.