forked from github/cordova-android
添加物理按键监听
添加物理按键监听
This commit is contained in:
parent
c9108d8479
commit
7ccefe4ba7
@ -1,41 +1,61 @@
|
|||||||
/*
|
/*
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
distributed with this work for additional information
|
distributed with this work for additional information
|
||||||
regarding copyright ownership. The ASF licenses this file
|
regarding copyright ownership. The ASF licenses this file
|
||||||
to you under the Apache License, Version 2.0 (the
|
to you under the Apache License, Version 2.0 (the
|
||||||
"License"); you may not use this file except in compliance
|
"License"); you may not use this file except in compliance
|
||||||
with the License. You may obtain a copy of the License at
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
Unless required by applicable law or agreed to in writing,
|
||||||
software distributed under the License is distributed on an
|
software distributed under the License is distributed on an
|
||||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
KIND, either express or implied. See the License for the
|
KIND, either express or implied. See the License for the
|
||||||
specific language governing permissions and limitations
|
specific language governing permissions and limitations
|
||||||
under the License.
|
under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package __ID__;
|
package __ID__;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import org.apache.cordova.*;
|
import org.apache.cordova.*;
|
||||||
|
import android.view.KeyEvent;
|
||||||
public class __ACTIVITY__ extends CordovaActivity
|
|
||||||
{
|
public class __ACTIVITY__ extends CordovaActivity
|
||||||
@Override
|
{
|
||||||
public void onCreate(Bundle savedInstanceState)
|
private static final int[] SCAN_KEYCODE = {520, 521, 522, 523};
|
||||||
{
|
|
||||||
super.onCreate(savedInstanceState);
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState)
|
||||||
// enable Cordova apps to be started in the background
|
{
|
||||||
Bundle extras = getIntent().getExtras();
|
super.onCreate(savedInstanceState);
|
||||||
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
|
|
||||||
moveTaskToBack(true);
|
// enable Cordova apps to be started in the background
|
||||||
}
|
Bundle extras = getIntent().getExtras();
|
||||||
|
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
|
||||||
// Set by <content src="index.html" /> in config.xml
|
moveTaskToBack(true);
|
||||||
loadUrl(launchUrl);
|
}
|
||||||
}
|
|
||||||
}
|
// Set by <content src="index.html" /> in config.xml
|
||||||
|
loadUrl(launchUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode >= SCAN_KEYCODE[0] && keyCode <= SCAN_KEYCODE[SCAN_KEYCODE.length - 1]) {
|
||||||
|
}
|
||||||
|
loadUrl("javascript:cordova.fireWindowEvent('native.onKeyUp',{keycode:"+keyCode+"})");
|
||||||
|
return super.onKeyUp(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode >= SCAN_KEYCODE[0] && keyCode <= SCAN_KEYCODE[SCAN_KEYCODE.length - 1]) {
|
||||||
|
}
|
||||||
|
loadUrl("javascript:cordova.fireWindowEvent('native.onKeyDown',{keycode:"+keyCode+"})");
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user