I want to disable incoming call and text notification and use my app to show notification.
Logic is that my app will stay in background and on incoming call/text my app will popup with a page where I will show notification.
Please can anyone help me how Can I disable default incoming call/text notification.
I was able to hide incoming call notifications by using full screen activity.
incoming call notification is not visible only activity is visible.
obviously you need to create service to detect incoming call which will launch your activity.
Here is code I used for full screen activity
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().getDecorView().setSystemUiVisibility(getSystemUiFlags());
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.myviewxml);
}
the function
private static int getSystemUiFlags() {
return View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
The manifest entry
<activity
android:name=".MyActivity"
android:label="#string/title_activity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"></activity>
Hope this helps somebody.
Related
Currently, I am working with an app in which there is a functionality in which user clicks on a button and user is navigated directly to settings screen. Now, whenever user is on settings screen at that time I want to disable the interaction of user with notification bar. I have a service & receiver in my code and tried to set the disable notification code in service class but can't able to achieve this.
View decorView = context.getSystemService(Context.WINDOW_SERVICE).getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
I tried to use this but not able to succeed. Any help will be appreciable.
There is an emergency app named Medical Id. It has a marvelous feature in which it shows notification on locked screen. The user can just double tap on the notification to open the activity. For other app notifications, if the user tap, it prompts for unlocking first. I am looking for the same feature but unable to achieve the same. I have tried adding flags to the attached windows.
#Override
public void onAttachedToWindow()
{
super.onAttachedToWindow();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON &
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD &
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED &
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON &
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
}
Added shownonlockscreen to the activity in the manifest as well, But it prompts for unlocking the screen before opening the activity. Have a look on the medical id for clarity. I don't know what they are using to bypass unlock. The phone settings for notifications are public in my phone. The amazing part is even if your phone notification setting is private, medical id notification will be present there even when no else notification is present. Any leads is helpful.
You should use pipes | instead of ampersands &
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
Also this only works above Android 4.4
if you want to show Activity on click of your notification from lock screen, you can do like this in OnCreate of your Activity lifecycle
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setTurnScreenOn(true);
setShowWhenLocked(true);
} else {
window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
}
}
i have two questions:
one how can i run my application in full screen
how video players run videos in full screen.
i have tried alot and still struggling to achieve this but couldn't find a solution.
the list of solution i found but they are not fulfilling my requirements
this hides only the notification bar.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
also hides only the notification bar
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
it low profiles the navigation bar not hiding it.
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
no effect on my activity.
anyView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
note that:
i am not talking about rooting a device,so please provide those solutions which can work without rooting a device.
i am not talking about hiding only notification bar,but full screen by hiding both navigation bar and notification bar too.
i am talking about jelly beans api 4.1 or greater than 4.1 version of android
and please give answers with code.
after my research and your answers, i am getting this:
but my app should look like this without navigation bar:
i do not want the system navigation bar visible in my app.
I'm not sure what you're after, but the following hides the Notification bar, and the Soft Navigation keys (as seen on Google Nexus-devices), so the app essentially is "full screen".
Edit2
In Android 4.4 (API 19) Google introduced the new Immersive mode which can hide the status & navbar and allow for a truly fullscreen UI.
// This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
Reference:
https://developer.android.com/training/system-ui/immersive.html
Edit:
Tested on Android 4.3 (API 18) and Android 4.1 (API 16) with Soft Nav keys.
#Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.main);
int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
}
For more information read up on http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility(int)
-To hide Status bar:
A great solution I found for that issue, setting each Activity theme & windowSoftInputMode to the following values :
<activity android:name=".MyActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="adjustResize"> <!-- theme : to set the activity to a full screen mode without a status bar(like in some games) -->
</activity> <!-- windowSoftInputMode : to resize the activity so that it fits the condition of displaying a softkeyboard -->
for more info refer here.
-To hide Notification bar:
There are Two ways :
1- root your device, then open the device in adb window command, and then run the following:
adb shell >
su >
pm disable com.android.systemui >
and to get it back just do the same but change disable to enable.
2- add the following line to the end of your device's build.prop file :
qemu.hw.mainkeys = 1
then to get it back just remove it.
and if you don't know how to edit build.prop file:
download EsExplorer on your device and search for build.prop then change it's permissions to read and write, finally add the line.
download a specialized build.prop editor app like build.propEditor.
or refer to that link.
On the new android 4.4 you should add this line:
View.SYSTEM_UI_FLAG_IMMERSIVE;
So the new working solution atleast on nexus4 4.4.2 is
final int mUIFlag =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE;
Immersive alone won't work though it works when combined with other flags. see documentation for more details.
Then you add in the activity the activating of this setup as shown here before (I am just adding for consistency)
getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
I made 2 layouts one for regular size and one for full screen and inside full scrreen I get the devices size and and assign it to video player
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);
int w=size.x;
int h=size.y;
videoPlayer.setFixedSize(w, h);
I think you cant hide the system bar in android 4.0 > (only in tablets, in phones you should be able to)
What you can do is to hide the icons and to disable some buttons(everyone except home)
You can try this:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
Also for disabling the buttons:
This is for back button:
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
This for the menu:
#Override
public void onWindowFocusChanged(boolean hasFocus) {
try
{
if(!hasFocus)
{
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method collapse = statusbarManager.getMethod("collapse");
collapse .setAccessible(true);
collapse .invoke(service);
}
}
catch(Exception ex)
{
}
}
Video Players run in full screen by setting the
myView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
setFlags() before setContentView(View)
This will show the system bar on any user interaction, just like video players do.
The closest you can get to running your app full screen is by setting in Lights Out mode, the system buttons will appear as dots.
To use the lights out mode just use any view in your activity and call
anyView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
For Hiding the navigation bar use this in your onStart() so that every time you get to that activity it will be in full screen mode.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
I hope this helps !
Android Version: 4.2.2 - Device: Vega Tablet
Android App to Hide Status and System Bar and displaying complete screen I followed these steps.
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity.java
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(0x10);
setContentView(R.layout.activity_main);
Above code perfectly worked for my app.
go to your manifest and add this to your activity
<activity
android:name="yourPackage.yourActivity"
android:theme="#android:style/Theme.Black.NoTitleBar">
i create a lockscreen application.. this application is triggered by SMS.. when a SMS containing command was received, it will display a lock screen activity.
my lockscreen activity is using TYPE_KEYGUARD for disabling a home screen button. When device screen turn off and then i turn it on again, my problem is status bar / notification bar still appear on my screen. this is a problem because the user still can access some program through status bar / notification bar even the device is being locked. so i want to dissapear this status bar / notification bar so that the user (theft) can't access that device anymore..
Please help me to solve this..
I think what you're trying to do is programmatically set an activity as fullscreen. If so, consider the following:
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
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
requestWindowFeature(Window.FEATURE_NO_TITLE);
only disables the activity's title bar, not the notification bar at the top.
Use this theme in android manifest for your activity :
"Theme.NoTitleBar.Fullscreen"
did work for me.
It hides the notification bar.
On Android 4.0 and lower
Option 1:
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
Option 2:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
...
}
on Android 4.1 and Higher
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
And for Android 4.6(Api 19) and higher use the Immersive Full-Screen
Mode
Reference from Google
I'm making my alarm app. There is an Activity to show alarm infomation.
I want turn on the screen and unlock it. I wrote these code
AlarmActivity.java:
public class AlarmActivity extends Activity {
......
void onCreate(Bundle bl) {
.....
final Window win = getWindow();
win.requestFeature(android.view.Window.FEATURE_NO_TITLE);
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
LayoutInflater inflater = LayoutInflater.from(this);
setContentView(inflater.inflate(R.layout.alarm, null));
}
......
}
AndroidManifest.xml
{activity android:name="AlarmTaskActivity"
android:excludeFromRecents="true"
android:theme="#android:style/Theme.Wallpaper.NoTitleBar"
android:launchMode="singleInstance"
android:taskAffinity=""
android:configChanges="orientation|keyboardHidden|keyboard|navigation"/}
It's ok,but when I change
android:theme="#android:style/Theme.Wallpaper.NoTitleBar"
to
android:theme="#android:style/Theme.Dialog"
the screen did not turn on nor unlock, I am really confused....
Can you please tell me how to make the screen turn on and unlock when I use "#android:style/Theme.Dialog"?
Thanks
by the way,I have android 2.0 in my test device.
In order to activate the screen and force it to stay on, you need to use a WakeLock. See the documentation for more information. Changing the theme along won't cause the screen to wake up. You'll need to use the ACQUIRE_CAUSES_WAKEUP flag in order to do that.