Skip to content

Commit 84cc7a7

Browse files
committed
press back twice to exit on Android
1 parent 1e832d0 commit 84cc7a7

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

platforms/android/AndroidManifest.xml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="cn.imaq.missionhelper" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
4+
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
7+
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
8+
<uses-permission android:name="android.permission.INTERNET" />
9+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
10+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
11+
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
12+
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
13+
<intent-filter android:label="@string/launcher_name">
14+
<action android:name="android.intent.action.MAIN" />
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
<service android:name="com.amap.api.location.APSService" />
19+
<meta-data android:name="com.amap.api.v2.apikey" android:value="92f2a8906b924832b9d1e3994453aadf" />
20+
</application>
21+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
22+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
23+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
package cn.imaq.missionhelper;
21+
22+
import android.os.Bundle;
23+
import android.provider.Settings;
24+
import android.webkit.WebView;
25+
import android.widget.Toast;
26+
27+
import com.amap.api.location.AMapLocation;
28+
import com.amap.api.location.AMapLocationClient;
29+
import com.amap.api.location.AMapLocationClientOption;
30+
import com.amap.api.location.AMapLocationListener;
31+
32+
import org.apache.cordova.*;
33+
34+
public class MainActivity extends CordovaActivity
35+
{
36+
private AMapLocationClient locationClient = null;
37+
private long backTime = 0;
38+
39+
@Override
40+
public void onCreate(Bundle savedInstanceState)
41+
{
42+
super.onCreate(savedInstanceState);
43+
// Set by <content src="index.html" /> in config.xml
44+
loadUrl(launchUrl);
45+
}
46+
47+
@Override
48+
public void onDestroy() {
49+
super.onDestroy();
50+
if (locationClient != null) {
51+
locationClient.stopLocation();
52+
locationClient.onDestroy();
53+
}
54+
}
55+
56+
@Override
57+
public void onBackPressed() {
58+
long time = System.currentTimeMillis();
59+
if (time - backTime > 2000) {
60+
Toast.makeText(getApplicationContext(), "Press again to exit", Toast.LENGTH_SHORT).show();
61+
backTime = time;
62+
} else {
63+
System.exit(0);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)