How to exclude the my app screenshots showing recent apps - android

As per security concern screenshots of my app screen should not be shown in recent apps.
I have tried adding android:excludeFromRecents="true" in all activities on the manifest file. However, screenshots are shown in recent apps, can some help me to solve this issue?

excludeFromRecents excludes from recents which is not what you need. Try setting FLAG_SECURE:
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(LayoutParams.FLAG_SECURE,
LayoutParams.FLAG_SECURE);
setContentView(R.layout.main_layout;
}
}

Related

Implementing launch screen for android with Delphi/Firemonkey

reading the https://developer.android.com/topic/performance/vitals/launch-time about the right way to implement a launch screen they say to create a Launcher style
<activity ...
android:theme="#style/AppTheme.Launcher" />
and they say that the easiest way to transition back to your normal theme is to call setTheme(R.style.AppTheme) before calling super.onCreate() and setContentView():
KOTLIN
JAVA
public class MyMainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate
setTheme(R.style.Theme_MyApp);
super.onCreate(savedInstanceState);
// ...
}
}
problem is with delphi, when/where can I call setTheme(R.style.Theme_MyApp); ? from inside the form create it's not work so seam already too late, and even just after Application.Initialize it's seam to not work either :(

Enable taking screenshot of a App after disabled using FLAG_SECURE

Using the code below I prevent users taking screenshots of my app. I want to implement "enable screenshot button". Is it possible? Which concept should I use?
public class FlagSecureTestActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(LayoutParams.FLAG_SECURE,
LayoutParams.FLAG_SECURE);
setContentView(R.layout.main);
}
}
You could restart the activity and this time not set the SECURE flag.
In my app, I have a switch in settings to enable or disable the secure flag. Then I simply do not set it if the settings specifies that I am allowed to take screenshots.

Why is my activity restarted despite all my efforts

This is not a question of how I can avoid my activity restart and recreation on say config changes lie e.t.c This is a question of why, despite all my efforts, my activity still restarts.What could be the possible reason?
Here is my scenario.
My app a text editing application, with tabs, so I implemented a custom TabHost and a custom TabWidget. The app has the MainActivity and a single fragment, MainFragment.
On To ensure instance is retained in my MainFragment, I have these:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
setHasOptionsMenu(true);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
To ensure MainActivity instance is retained, I have this:
/**
* #see android.app.Activity#onCreate(android.os.Bundle)
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frame = new FrameLayout(this);
frame.setId(android.R.id.content);
setContentView(frame, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
actionBar = getSupportActionBar();
if ((MyTextEditor.isSmallScreenSize(getResources()) || MyTextEditor.isNormalScreenSize(getResources()))
&& getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ) {
actionBar.setDisplayShowTitleEnabled(false);
}
if (savedInstanceState != null) {
editorFrag = (MyTedFragment) getSupportFragmentManager().getFragment(
savedInstanceState, "editor");
}
if (editorFrag == null) {
editorFrag = new MyTedFragment();
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, editorFrag).commit();
}
....
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, "editor", editorFrag);
}
And the following in my AndroidManifest.xml
<application
android:name="com.myapp.MyApp"
android:debuggable="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyAppTheme" >
<!-- Ted main activity ... ie a text field :)
android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="adjustResize"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|fontScale|screenSize|smallestScreenSize">
-->
<activity
android:name="com.myapp.texteditor.MainActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|fontScale|screenSize|smallestScreenSize"
android:launchMode="singleTask" android:windowSoftInputMode="adjustResize">
</activity>
....
</application>
Now the problem:
CASE 1: Android version: 2.3.6 Gingerbread on Samsung device
If I push my activity to the background and I relaunch my app in less than about 3 minutes , the main activity instance is restored just fine.
If I choose to relaunch my app after a while longer, say 10 min or so,the app restarts afresh and this is bad for my app because if a user had any unsaved changes, they are lost.
CASE 2:
Android Version: 4.3, running on Emulator
How long I choose to wait before relaunching the app, the instance is always restored. Looks like everything works fine.
What could be the reason for this? Is this associated with a bug around the activity life cycle or Activity Manager for Gingerbread?
Your 1st case is something that you can't really avoid. A real device can not keep your activities around for forever (memory pressure etc). If your app is in the background then it's considered not important for the user (as he's not interacting with it) and it's a good target for the OS to kill if needed.
A perhaps useful option is SharedPreference.
This data will live until app is uninstalled but require a String key for each data entry, that it, is it not useful if the fragments are highly dynamic, though it often is possible to work around using arrays and the like.
Look at my answer to How to maintain fragment's state in the application for an example.

Android: How to restart activity?

I made 2 activities.
e.g] MainActivy and MediaActivity.
If user click home button in MediaActivity, App will hide.
I want launch MediaActivty again when screen on.
Open the gmail app, tap on an email to show it's contents. You have now gone from one activity (email list) to another (email details). Press the home button. Now open the gmail app again. Voila! You have returned to the email you selected.
What you ask for is the default behavior of an Android app. Unless you do something like call finish() in your onPause() method in MediaActivity you should return to MediaActivity when you open the app again.
If your app doesn't behave like this I suggest that you post some code.
Try to write your activities the following way :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Put your own code here.
}
}
public class MediaActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Put your own code here.
}
}
What you're asking is Up Navigation / Ancestral Navigation(if I understood it correct). Refer to this guide: http://developer.android.com/training/implementing-navigation/ancestral.html
Othewise, if you want to have multiple instances of an activity, it's android:launchMode property should be set to standard in manifest. Refer:
http://developer.android.com/guide/topics/manifest/activity-element.html

Show black preview screen in task manager on ICS

I want to show a black screen in the task manager preview under Ice Cream Sandwich, like the German 'finanzstatus' app does. It would be nice if someone could point me in the right direction.
Using FLAG_SECURE will block your app from screenshots, including the recent tasks list:
public class FlagSecureTestActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(LayoutParams.FLAG_SECURE,
LayoutParams.FLAG_SECURE);
setContentView(R.layout.main);
}
}

Categories

Resources