I want change this message "Your phone is shut down" that appear when shut down the device.
Do you have any ideas?
My app download videos in the background, I must warn you not to switch off the device if the download is not yet finished, such as happens when you shut down Windows and is downloading updates.
Adriana take a look at Intent.ACTION_SHUTDOWN, i am not sure if you can handle like you want.
Additionally this post is related to this.
In AndroidManifest.xml:
<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.DEVICE_POWER"
tools:ignore="ProtectedPermissions" />
MainActivity.java I intercept the power off button and force close system dialog and create a View custom above it
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_POWER) {
// Do something here...
event.startTracking(); // Needed to track long presses
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeDialog);
mViewCustom.setVisibility(View.VISIBLE);
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_POWER) {
return true;
}
return super.onKeyLongPress(keyCode, event);
}
Related
I am trying to add shortcuts in my app when external keyboard is connected. SHIFT+KEY, this combination is triggering the following event. But Control+KEY and Control key events are not triggered. Can anyone suggest me on this.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_CTRL_LEFT) {
flag_sellreceipt = KeyEvent.isModifierKey(KeyEvent.KEYCODE_CTRL_LEFT);
int i = KeyEvent.META_CTRL_LEFT_ON;
System.out.println("ctrl is pressed");
}
return
super.onKeyDown(keyCode, event);
}
Note: I have tested this in emulator.
Is it possible for an Android application to intercept external keyboard shortcuts (e.g. Alt+Tab) and action them before the OS performs the default behaviour? Using Alt+Tab as an example, I would like to be able to have my app respond to Alt+Tab within my application and not have Android switch applications to a different app.
I have tried searching, but have not been able to find an answer, I think my Google-Fu is failing me!
It maybe is not as extense or detailed as it would be needed for capturing a shortcut, but you may want to override the onKeyDown event in your activity.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
Log.d(this.getClass().getName(), "Back button pressed");
}
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
Log.d(this.getClass().getName(), "Home button pressed");
}
if ((keyCode == KeyEvent.KEYCODE_MENU)) {
Log.d(this.getClass().getName(), "Menu button pressed");
}
//return true;
return super.onKeyDown(keyCode, event);
}
I have done the following changes into my code. I just want to clear the call log that written by the SIP phone, I have made my SIP phone using SIPDROID.
If I delete the permissions from Android manifest it gives me an error.
All I want is to remove the dialed call logs into the recent calling history.
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
Log.e("Test", "Back button pressed!");
}
else if(keyCode == KeyEvent.KEYCODE_HOME)
{
Log.e("Test", "Home button pressed!");
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
I've noticed that the 'back' request used to be made at the point a user pressed down on the 'back' key but at some point this was changed so that a 'back' request is made instead at the point the 'back' key is released. (Correct me if I am wrong!) Does anyone know from which SDK (or API Level) exactly this change was made effective? I think it was SDK 2.0 (API Level 5) and hence have the code in my Activity as follows but would like to be certain...
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR)
handleBackRequest();
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ECLAIR)
handleBackRequest();
return true;
}
return super.onKeyUp(keyCode, event);
}
Use onBackPressed() for Android 2.0 and higher. Use onKeyDown() for Android 1.6.
With the code in my previous post I was getting some unwanted behaviour (when dialogs, the android keyboard etc were showing up) and on CommonsWare's advice, changed my code to the following and it seems to be working alright for the different SDKs...
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK
&& android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR)
{
onBackPressed();
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public void onBackPressed()
{
// handle back request here
}
... Let me know please if there's anything here not quite right!
I am sincerely trying to display alert box onClick of Home key, but I am not succeeded. So please help me to write the code otherwise, show me the code.
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK )
{
finish();
return false;
}
else if (keyCode == KeyEvent.KEYCODE_HOME)
{
finish();
return false;
}
return super.onKeyDown(keyCode, event);
}
it is not possible to intercept KEYCODE_HOME by external applications:
http://code.google.com/p/android/issues/detail?id=1979
I don't think you can intercept HOME key presses. It is reserved to ensure that you don't get locked within any application.
KEYCODE_HOME : This key is handled by the frame work and is never delivered to applications.
So you can't use it