Android - How to Block the Notification Manager When our App Runs - android

I want to know how I can disable or block the Notification Manager, while my application is running.
Meaning that the user cannot use the Notification Manager, ie a notification should not pop up.

You have to make it fullscreen, either:
Via manifest:
<activity ...
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
</activity>
Or via code:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

I think you want to set activity as full screen. If so, try this it might help you.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Source: http://www.androidsnippets.com/how-to-make-an-activity-fullscreen

By blocking the notification manager do you mean blocking notifications from your app when your app is in the foreground? I'm looking for something similar, and I think creating a service to manage notifications that are shown that can be messaged by activities when they start and stop may be what is needed.

Related

Show *only* a toast (no UI) after sharing text into an app?

I'm a starting Android developer and would like to know how to achieve this:
1# User is using e.g. Chrome
2# User wants to share the page (meaning: the URL, which is text) into an app
3# User chooses the app from the share menu
4# The app shows only a small notification on top of Chrome (current foreground app, which is the sender of the intent)
So the app would receive the intent from Chrome and do something with it, but wouldn't change the foreground app. It would stay in the background and show only a very small notification to the user that the sharing of the URL into this app actually succeeded. Toast or something like that.
This is basically the way for instance Pocket handles sharing into it.
How can I achieve this? IntentService? I cannot seem to find the correct answer to this. Theme.NoDisplay, Intent, IntentService – I cannot figure out the correct way since I'm not too familiar with Android yet.
Thank you a lot in advance!
Use the NoDisplay theme (update activity declaration in manifest) in the activity that does your sharing work as follows:
android:theme="#android:style/Theme.NoDisplay"
This will prevent the activity from being displayed.
Then once the activity starts, do your sharing task, display the Toast and call finish()
finish your activity onResume(). It will not shows any of Your Activity.
You can do like this:
protected void onResume() {
super.onResume();
finish();
}

Disable System bar Android 4.0

I know there has been lot of discussion for hiding system bar on android 4.0 but no discussions on disabling the functionality of virtual button or status bar or system bar on Android 4.0 tablets?
Is this possible? Can somebody guide me to the right direction?
Thanks!
Try FLAG_FULLSCREEN, it should hide the status bar
http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN
I have done a lot of research to design a lock screen and finally found a solution to permanently disable System bars i.e Navigation bar(Back, home, Recent apps soft keys) and the status bar. Android disabled the feature to override System bars except the back button. But there is a little work around to make this work:
Understand and implement screen pinning patiently and you will be successful.
You can create an app to control what all applications you want to implement screen pinning in or you can implement screen pinning directly in the same application you want to pin.
I'm going to show you the later implementation in this article:
1. Firstly your app should be the device owner.
You can do it in several ways and the easiest is to execute the command:
adb shell dpm set-device-owner [yourPackageName]/.[MyDeviceAdminReceiver]
Create a receiver(MyDeviceAdminReceiver) that extends DeviceAdminReceiver. You needn't have any code in here. For more info on Device owner implementation refer this link
http://florent-dupont.blogspot.com/2015/02/10-things-to-know-about-device-owner.html
Register the receiver in the AndroidManifest.xml file this way :
<receiver
android:name=".MyDeviceAdminReceiver"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
2. Your onCreate method should look like this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lock_screen);
ComponentName deviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);
DevicePolicyManager mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
if (mDpm.isDeviceOwnerApp(getPackageName())) {
mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
}
if (mDpm.isLockTaskPermitted(this.getPackageName()))
startLockTask();
3.To unpin the screen and make Navigation Bar functional:
Call the function stopLockTask() at a place in your code where you want to unpin. For example in my application, as soon as I verify that the user has typed the correct passcode, I call this function:
if (userInput.length() == 4) {
if (userInput.equals(passcode)) {
userInput = "";
etxtPasscodeDisplay.setText("");
stopLockTask(); // this is what you need
unlockHomeButton(); // A method to show home screen when
passcode is correct
finishAffinity(); //kill other activities
}
Extra Info which usually is required for lockscreens:
1. If your app is the first thing that comes up after boot:
You need a service(StartAtBootService) and a receiver (BootCompletedReceiver) for this.
2. If you want your app to show up after screen lock and unlock
(the power button is pressed to lock and unlock):
Create AEScreenOnOffService that extends service and AEScreenOnOffReceiver that extends BroadcastReceiver to launch your activity when the screen is on.
For a detailed info on everything I mentioned here, refer http://www.sureshjoshi.com/mobile/android-kiosk-mode-without-root/
This is an excellent write up which helped me a lot. Special thanks to the author.
I need at least 10 reputation to post more than two links. As I'm new to stackoverflow I don't have enough reputation so I'm sorry for not being able to share all the links I referred. Will surely update the post once I get access.

ANDROID : Activity gets destroy in sleep mode

I am facing issue in Activity which is calling from Broadcast receiver.
My application contains alarm system, so when time of alarm match, at that time, broadcast receiver calls one activity to get in front. This activity is not in full screen, it is one type of alert box using RegionSearchDialog as theme. (Don't be confuse, I am using activity only, my class extends activity, but the theme in xml set as RegionSearchDialog)
My platform of development is: 4.0.4
Now my issue is: if my device is on (unlock keygurad) either application is in front or in back, it works fine. But if power is off (sleep mode / device is lock), it will call same activity, onCreate() calls first then onResume() and then it will call onPause() as my device is in sleep mode.
I want to keep that activity running, don't want to get it sleep.
So, when alarm time match, it will buzz alarm and if its in sleep mode then user can unlock device and see popup of that alarm.
Thanks in advance to help me in that.
This is the way Activities in Android are supposed to work. You would be better using a Service or using the Alarm manager to launch an Activity at a certain time as these are more suited to what you are trying to do =).
Here is my code,i think it can help you:
In your activity on create():
super.onCreate(savedInstanceState);
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
setContentView(R.layout.main);
and main xml is:
<activity
android:name=".main"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Wallpaper.NoTitleBar"
android:launchMode="singleInstance"
android:excludeFromRecents="true"
android:taskAffinity=""
android:configChanges="orientation|keyboardHidden|keyboard|navigation" />
pls test these code in your project. :)
In addition to the response by 'enjoy-writing':
It sufficed in my android app to set the flags as described in the onCreate code.
The effect was that the app would pause when going into sleep mode (e.g. through pressing the On/off button on the phone), and resume when returning from sleep mode.
By removing the FLAG_KEEP_SCREEN_ON flag you can still have the phone fall asleep if the view isn't used for a while.

Android app full screen

Got this app running in kiosk mode and would like to run it on full screen.
Already got rid of the application's grey title bar, but still got the home, volume, back and other buttons on the top bar as you can see in the picture.
The device is running android 2.2 firmware.
Any help is greatly appreciated!
So there is more approaches:
First, you should specify this feature in your Manifest.xml
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
Or in your onCreate method work both these approaches:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
or
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
The tablet you are running on is running a hacked version of Android, one that does not comply with the Compatibility Definition Document. As a result, you probably cannot get rid of that bar, unless you replace the firmware with something else.
The recommendations that the other provided is the right answer for compatible Android devices.
Make Your activity to look something like this in manifest
<activity
android:name=".HelloActivity"
android:label="#string/laptop"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
In android manifest use this line
<activity android:name=".yourActivityName"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">
and in your class use this line in oncreate method
requestWindowFeature(Window.FEATURE_NO_TITLE);
this code works fine for android 2.2 i have tested and its working.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity);

Android: Use FLAG_FULLSCREEN and TYPE_KEYGUARD together

I'm trying to do an Android-Tablet app for presentations on trade fairs etc. I don't want to upload the app to the app store, only use it on my tablet.
I try to run the app in ful screen mode (without status bar) with:
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Works great. I try to disable the home button with:
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
in my OnCreate-Method. Works great.
But if I try to use both in one app, only disabling the home button still works, any idea what i can do about this?
Thank you!
Try declaring the activity as fullscreen in AndroidManifest.xml, and then doing what you already do to capture the home button
<activity android:name="..." android:label="..."
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" />

Categories

Resources