I have an application which needs to run on handheld devices and on tablets/kiosks etc. as far as the design is concern it is easy to maintain but now I have two different logic which needs to different entry points on different device. Following is my requirements.
If it is phone, I want to show login/signup screen then after login/signup it will take to main screen
if it is not phone (I mean if it is tablet/kiosk) it will directly go to main screen.
How can I achieve this? I took some idea from this thread on SO. but it is too old. Is there any reliable advance way to do that what I need.
Please do not mark as copy and do not close it because I am asking for new way to do it. so that the newbies can get it easily on one thread.
there is no such option for different launchers on different devices, but you can always check what you need in one (and only?) laucher (onCreate method) and start immediately "main" Activity if needed with finishing current "login"
edit:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(checkIfTablet()) {
startActivity(new Intent(this, MainActivity.class));
finish;
return;
}
// rest of code
}
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)
today I used Android Studio 1.4 for the first time. I decided to make a app that helps you find a movie to watch. Very basic. Main page with a buttom that sends you to a random movie with tittle, poster, imdb link and a buttom that sends you to a new random movie.
I got two problems.
The Mainpage buttom that sends the user to a random activity is not working. How can i code it so it will send the user to a random activity and preferred not the same one. Can you make it choose from 1 of 100 activities?
I only get a error when I try to bind the Imdb link to a button.
Well your asking a question which requires to do some looking around. You are asking some basic question, which you should be able to do.
Here is a little code that you can use
Button yourButton = (Button) findViewById(R.id.your_buttons_id);
yourButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
startActivity(new Intent(YourCurrentActivity.this, YourNewActivity.class));
}
});
I personally feel like you need to check some tuts online. This is the basic, if you struggle on this, then you would struggle a lot more else where.
Anyway, if you see findViewById(R.id.your_buttons_id); it lets the app know which button that was clicked.
I'm very new to programming with Android, so I'm making a simple text RPG to practice developing for the platform. The player has access to a menu, which shows their items as a group of Radio Buttons. That way one can be selected to Equip/sell/etc. The game is handled in a completely different Activity. I want a random event that can happen in the Game activity to be able to add a new custom Radio button to the Inventory Activity page. On my Inventory Activity page, I've written a simple method:
public void addRadioButtons(){
RadioGroup items=(RadioGroup) findViewById(R.id.invItems);
RadioButton newItem = new RadioButton(this);
newItem.setText("New Rare Item");
newItem.setId(idCounter);
idCounter++;
items.addView(newItem);
}
When the random drop event is calculated in the Game Event, it just does a object.addRadioButtons() method call. This force closes every time, no matter what I try. I've also tried pre-formatting the button before adding it, also to no avail. Am I missing something?
It seems, that the reason in idCounter value. In Android view id must be calculated according to certain rules. Look at this post for more detals.
I am new to Blackberry devlopment and i have created 3 screens for the Blackberry application. Now my question is how to link these screens like if iam on 1st screen and if i click a button like submit it should go to the next screen like this it should go from 2nd screen to 3rd screens.
thanks
UiApplication.getUiApplication().pushScreen(yourNextScreen);
See the documentation on RIM website.
You add a listener (I have given code for the trackwheelClick listener below, but you can use others as well depending on if you want a keypress or touch etc.
I have written in the matter of implementing the event on the instantiated object itself, but you can also subclass ButtonField if you really want to.
ButtonField closeButton = new ButtonField("Close") {
public boolean trackwheelClick(int status, int time) {
UiApplication.getUiApplication().pushScreen(new NextScreen());
return true;
}
};