android


Android Multiple Button Press


How to make when press multiple keys at same time (like when booting recovery and download mode using power and volume keys) start new activity in android application?
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN))
{
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
return true;
}
Try the following solution, it is tested and it works!
public class MainActivity extends AppCompatActivity {
private boolean isVolumeUpPressed = false;
private boolean isVolumeDownPressed = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
this.isVolumeDownPressed = true;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
this.isVolumeUpPressed = true;
}
if (this.isVolumeUpPressed && this.isVolumeDownPressed) {
final Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
return super.onKeyUp(keyCode, event);
}
#Override
public boolean onKeyUp(final int keyCode, final KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
this.isVolumeDownPressed = false;
} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
this.isVolumeUpPressed = false;
}
return super.onKeyUp(keyCode, event);
}
}
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) && (keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {

Related Links

Getting “java.lang.RuntimeException: here” while starting application
Vungle video ad is not showing but audio is playing
VolleyError: java.lang.IllegalArgumentException: timeout < 0
Version Control from Android App
cannot install two flavors of an app with Android Annotations
Calculating dates from given two dates excluding weekend in android
When ListView is ready?
using java.awt classes in android
Switch to a nested PreferenceScreen from activity
How to display multiple camera previews with different effects?
Can I save the photo to RAM in Android without sd card
Wrong viewport height
Android - How to calculate tilt angles from accelerometer data?
Header image can't fit correctly (DrawerLayout)
How to use microsoft's thrifty over http?
TLS in Smack when connecting to XMPP server

Categories

HOME
notepad++
oracle12c
porting
time-complexity
appcelerator
google-apps
vsm
mvc5
pkcs#11
modal-dialog
okhttp
google-schemas
vimdiff
enthought
project-intu
mxgraph
rtf
php-5.6
shared-libraries
renjin
git-extensions
gulp-watch
google-api-client
gpio
appirater
ms-access-web-app
datastax-enterprise-graph
errbot
tizen-tv
carrierwave
failover
xbox
anki
login-script
instantiation
mnist
searchkit
python-pptx
hivemq
bc
hackintosh
serde
chai-as-promised
openblas
pair-programming
wpas
java-bytecode-asm
boxing
subnet
avx
bootstrap-tags-input
cudd
centrifuge
watch-os-2
windows-azure-queues
mediametadataretriever
dbamp
hadoop-partitioning
libav
crouton-os
fiware-monitoring
computer-architecture
vigenere
flock
django-urls
nutiteq
rrule
phpldapadmin
apache-spark-1.3
rapidsvn
cuba
dct
cfcache
syndicationfeed
ie8-compatibility-mode
ice-cube
cmmi
video-codecs
chart-director
booksleeve
os.system
iboutlet
thttpd
gobject-introspection
ikimagebrowserview
role
saxparseexception
matlab-load
uipagecontrol
django-paypal
presentation-layer
instantiationexception
folding
zend-rest
feasibility
sifr3
fail-fast-fail-early
product-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App