A. android是如何使用AndroidManifest.xml的
一、關於AndroidManifest.xml
AndroidManifest.xml 是每個android程序中必須的文件。它位於整個項目的根目錄,描述了package中暴露的組件(activities, services, 等等),他們各自的實現類,各種能被處理的數據和啟動位置。 除了能聲明程序中的Activities, ContentProviders, Services, 和Intent Receivers,還能指定permissions和instrumentation(安全控制和測試)
二、AndroidManifest.xml結構
<?xmlversion="1.0"encoding="utf-8"?>
<manifest>
<application>
<activity>
<intent-filter>
<action/>
<category/>
</intent-filter>
</activity>
<activity-alias>
<intent-filter></intent-filter>
<meta-data/>
</activity-alias>
<service>
<intent-filter></intent-filter>
<meta-data/>
</service>
<receiver>
<intent-filter></intent-filter>
<meta-data/>
</receiver>
<provider>
<grant-uri-permission/>
<meta-data/>
</provider>
<uses-library/>
</application>
<uses-permission/>
<permission/>
<permission-tree/>
<permission-group/>
<instrumentation/>
<uses-sdk/>
<uses-configuration/>
<uses-feature/>
<supports-screens/>
</manifest>
三、各個節點的詳細介紹
上面就是整個am(androidManifest).xml的結構,下面以外向內開始闡述~~
1、第一層(<Manifest>):(屬性)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.woody.test"
android:sharedUserId="string"
android:sharedUserLabel="string resource"
android:versionCode="integer"
android:versionName="string"
android:installLocation=["auto" | "internalOnly" | "preferExternal"] >
</manifest>
A、xmlns:android
定義android命名空間,一般為http://schemas.android.com/apk/res/android,這樣使得Android中各種標准屬性能在文件中使用,提供了大部分元素中的數據。
B、package
指定本應用內java主程序包的包名,它也是一個應用進程的默認名稱
C、sharedUserId
表明數據許可權,因為默認情況下,Android給每個APK分配一個唯一的UserID,所以是默認禁止不同APK訪問共享數據的。若要共享數據,第一可以採用Share Preference方法,第二種就可以採用sharedUserId了,將不同APK的sharedUserId都設為一樣,則這些APK之間就可以互相共享數據了。詳見:http://wallage.blog.163.com/blog/static/17389624201011010539408/
D、sharedUserLabel
一個共享的用戶名,它只有在設置了sharedUserId屬性的前提下才會有意義
E、versionCode
是給設備程序識別版本(升級)用的必須是一個interger值代表app更新過多少次,比如第一版一般為1,之後若要更新版本就設置為2,3等等。。。
F、versionName
這個名稱是給用戶看的,你可以將你的APP版本號設置為1.1版,後續更新版本設置為1.2、2.0版本等等。。。
G、installLocation
安裝參數,是Android2.2中的一個新特性,installLocation有三個值可以選擇:internalOnly、auto、preferExternal
選擇preferExternal,系統會優先考慮將APK安裝到SD卡上(當然最終用戶可以選擇為內部ROM存儲上,如果SD存儲已滿,也會安裝到內部存儲上)
選擇auto,系統將會根據存儲空間自己去適應
選擇internalOnly是指必須安裝到內部才能運行
(註:需要進行後台類監控的APP最好安裝在內部,而一些較大的游戲APP最好安裝在SD卡上。現默認為安裝在內部,如果把APP安裝在SD卡上,首先得設置你的level為8,並且要配置android:installLocation這個參數的屬性為preferExternal)
2、第二層(<Application>):屬性
一個AndroidManifest.xml中必須含有一個Application標簽,這個標簽聲明了每一個應用程序的組件及其屬性(如icon,label,permission等)
<application android:allowClearUserData=["true" | "false"]
android:allowTaskReparenting=["true" | "false"]
android:backupAgent="string"
android:debuggable=["true" | "false"]
android:description="string resource"
android:enabled=["true" | "false"]
android:hasCode=["true" | "false"]
android:icon="drawable resource"
android:killAfterRestore=["true" | "false"]
android:label="string resource"
android:manageSpaceActivity="string"
android:name="string"
android:permission="string"
android:persistent=["true" | "false"]
android:process="string"
android:restoreAnyVersion=["true" | "false"]
android:taskAffinity="string"
android:theme="resource or theme" >
</application>
A、android:allowClearUserData('true' or 'false')
用戶是否能選擇自行清除數據,默認為true,程序管理器包含一個選擇允許用戶清除數據。當為true時,用戶可自己清理用戶數據,反之亦然
B、android:allowTaskReparenting('true' or 'false')
是否允許activity更換從屬的任務,比如從簡訊息任務切換到瀏覽器任務
C、android:backupAgent
這也是Android2.2中的一個新特性,設置該APP的備份,屬性值應該是一個完整的類名,如com.project.TestCase,此屬性並沒有默認值,並且類名必須得指定(就是個備份工具,將數據備份到雲端的操作)
D、android:debuggable
這個從字面上就可以看出是什麼作用的,當設置為true時,表明該APP在手機上可以被調試。默認為false,在false的情況下調試該APP,就會報以下錯誤:
Device XXX requires that applications explicitely declare themselves as debuggable in their manifest.
Application XXX does not have the attribute 'debuggable' set to TRUE in its manifest and cannot be debugged.
E、android:description/android:label
此兩個屬性都是為許可提供的,均為字元串資源,當用戶去看許可列表(android:label)或者某個許可的詳細信息(android:description)時,這些字元串資源就可以顯示給用戶。label應當盡量簡短,之需要告知用戶該許可是在保護什麼功能就行。而description可以用於具體描述獲取該許可的程序可以做哪些事情,實際上讓用戶可以知道如果他們同意程序獲取該許可權的話,該程序可以做什麼。我們通常用兩句話來描述許可,第一句描述該許可,第二句警告用戶如果批准該許可權會可能有什麼不好的事情發生
F、android:enabled
Android系統是否能夠實例化該應用程序的組件,如果為true,每個組件的enabled屬性決定那個組件是否可以被 enabled。如果為false,它覆蓋組件指定的值;所有組件都是disabled。
G、android:hasCode('true' or 'false')
表示此APP是否包含任何的代碼,默認為true,若為false,則系統在運行組件時,不會去嘗試載入任何的APP代碼
一個應用程序自身不會含有任何的代碼,除非內置組件類,比如Activity類,此類使用了AliasActivity類,當然這是個罕見的現象
(在Android2.3可以用標准C來開發應用程序,可在androidManifest.xml中將此屬性設置為false,因為這個APP本身已經不含有任何的JAVA代碼了)
H、android:icon
這個很簡單,就是聲明整個APP的圖標,圖片一般都放在drawable文件夾下
I、android:killAfterRestore
J、android:manageSpaceActivity
K、android:name
為應用程序所實現的Application子類的全名。當應用程序進程開始時,該類在所有應用程序組件之前被實例化。
若該類(比方androidMain類)是在聲明的package下,則可以直接聲明android:name="androidMain",但此類是在package下面的子包的話,就必須聲明為全路徑或android:name="package名稱.子包名成.androidMain"
L、android:permission
設置許可名,這個屬性若在<application>上定義的話,是一個給應用程序的所有組件設置許可的便捷方式,當然它是被各組件設置的許可名所覆蓋的
M、android:presistent
該應用程序是否應該在任何時候都保持運行狀態,默認為false。因為應用程序通常不應該設置本標識,持續模式僅僅應該設置給某些系統應用程序才是有意義的。
N、android:process
應用程序運行的進程名,它的默認值為<manifest>元素里設置的包名,當然每個組件都可以通過設置該屬性來覆蓋默認值。如果你想兩個應用程序共用一個進程的話,你可以設置他們的android:process相同,但前提條件是他們共享一個用戶ID及被賦予了相同證書的時候
O、android:restoreAnyVersion
同樣也是android2.2的一個新特性,用來表明應用是否准備嘗試恢復所有的備份,甚至該備份是比當前設備上更要新的版本,默認是false
P、android:taskAffinity
擁有相同的affinity的Activity理論上屬於相同的Task,應用程序默認的affinity的名字是<manifest>元素中設定的package名
Q、android:theme
是一個資源的風格,它定義了一個默認的主題風格給所有的activity,當然也可以在自己的theme裡面去設置它,有點類似style。
不過現在在android stuido 上面 版本控制已經使用Gradle了。
B. 安卓開發 failed to get ged log buf,err怎麼解決
是因為android的插件沒有安裝,需要安裝插件。
操作步驟:
1、點擊「settings」選項。
注意事項:
1、Unix/Linux平台技術:基本命令,Linux下的開發環境。
2、企業級資料庫技術:SQL語言、SQL語句調優、Oracle資料庫技術。
3、Java 語言核心技術:Java語言基礎、Java面向對象編程、JDK核心API、Java集合框架、Java網路編 程、JavaI/O編程、Java多線程編程、Java異常機制、Java安全、JDBC、XML。
4、軟體工程和設計模式:軟體工程概述、配置管理及SVN、UML、基本設計模式。
C. 我用eclipse寫的android聊天軟體連接不到本地openfire,初始配置都是從網上參考的,就是不行,
填你的電腦的ip,別用127.0.0.1,這個表示Android自己本機
D. android中mqtt怎麼做
MQTT連接建立的代碼(SSL方式)
[java] view plain
public static void connect(Driver driver) {
ServerConfig serverConfig = UserMole.Instance.getServerConfig();
MqttConnectOptions conOpt = new MqttConnectOptions();
try {
SSLContext sslContext;
KeyStore ts = KeyStore.getInstance("BKS");
ts.load(context.getResources().openRawResource(R.raw.test_cert),
"123456".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(ts);
TrustManager[] tm = tmf.getTrustManagers();
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tm, null);
SocketFactory factory = sslContext.getSocketFactory();
conOpt.setSocketFactory(factory);
} catch (Exception e) {
e.printStackTrace();
}
<span style="white-space:pre"> </span>
[java] view plain
<span style="white-space:pre"> </span>//paho庫得
Iterator<Map.Entry<String, Connection>> it = Connections
.getInstance(context).getConnections().entrySet().iterator();
while (it.hasNext()) {
MqttClientAndroidService detectClient = it.next().getValue()
.getClient();
try {
detectClient.disconnect();
} catch (MqttException e) {
e.printStackTrace();
}
it.remove();
}
// The basic client information
MqttClientAndroidService client;
client = Connections.getInstance(context).createClient(context,
serverConfig.getUri(), serverConfig.clientId);
Integer qos = Integer.parseInt(context.getResources().getString(
R.string.qos));
Boolean retained = Boolean.parseBoolean(context.getResources()
.getString(R.string.retained));
// connection options
int timeout = Integer.parseInt(context.getResources().getString(
(R.string.timeout)));
int keepalive = Integer.parseInt(context.getResources().getString(
R.string.keepalive));
Connection connection = new Connection(serverConfig.getClientHandle(),
serverConfig.clientId, serverConfig.server,
Integer.parseInt(serverConfig.port), context, client,
serverConfig.ssl);
// connection.registerChangeListener(changeListener);
// connect client
String[] actionArgs = new String[1];
actionArgs[0] = serverConfig.clientId;
connection.changeConnectionStatus(ConnectionStatus.CONNECTING);
boolean cleanSession = false;
conOpt.setCleanSession(cleanSession);
conOpt.setConnectionTimeout(timeout);
conOpt.setKeepAliveInterval(keepalive);
if (!TextUtils.isEmpty(serverConfig.user)) {
conOpt.setUserName(serverConfig.user);
}
if (!TextUtils.isEmpty(serverConfig.pwd)) {
conOpt.setPassword(serverConfig.pwd.toCharArray());
}
// conOpt.setPassword("1111".toCharArray());
final ActionListener callback = new ActionListener(context,
ActionListener.Action.CONNECT, driver.getMqttUtilsCallback(),
serverConfig.getClientHandle(), actionArgs);
boolean doConnect = true;
String message = ActivityConstants.message;
String topic = ActivityConstants.topic;
if ((!TextUtils.isEmpty(message) || !TextUtils.isEmpty(topic))) {
// need to make a message since last will is set
try {
conOpt.setWill(topic, message.getBytes(), qos.intValue(),
retained.booleanValue());
} catch (Exception e) {
e.printStackTrace();
doConnect = false;
callback.onFailure(null, e);
}
}
client.setCallback(new MqttCallbackHandler(context, serverConfig
.getClientHandle(), driver));
connection.addConnectionOptions(conOpt);
Connections.getInstance(context).addConnection(connection);
if (doConnect) {
try {
client.connect(conOpt, null, callback);
} catch (MqttException e) {
Log.e(TAG, "MqttException Occured", e);
}
}
}
發布(publish)代碼
[java] view plain
public static void publish(String clientHandle, String topic,
JSONObject jsonObj, int qos) {
MqttClientAndroidService client = Connections.getInstance(context)
.getConnection(clientHandle).getClient();
if (!isConnected(context)) {
try {
client.connect();
} catch (MqttException e) {
e.printStackTrace();
}
Toast.makeText(context, "please try again", Toast.LENGTH_SHORT)
.show();
return;
}
if (topic == null) {
Toast.makeText(context, "can not get other's identity for now",
Toast.LENGTH_SHORT).show();
return;
}
String[] args = new String[2];
if (jsonObj.optLong("time") != 0) {
args[0] = String.valueOf(jsonObj.optLong("time"));
args[1] = topic;
}
Boolean retained = Boolean.parseBoolean(context.getResources()
.getString(R.string.retained));
try {
client.publish(topic, jsonObj.toString().getBytes(), qos, retained,
null, new ActionListener(context, Action.PUBLISH, null,
clientHandle, args));
} catch (MqttSecurityException e) {
Log.e(TAG,
"Failed to publish a messged from the client with the handle "
+ clientHandle, e);
} catch (MqttException e) {
Log.e(TAG,
"Failed to publish a messged from the client with the handle "
+ clientHandle, e);
}
}
訂閱(subscribe)代碼
[java] view plain
public static void subscribe(MqttUtilsCallback mqttUtilsCallback,
String clientHandle, String topic) {
MqttClientAndroidService client = Connections.getInstance(context)
.getConnection(clientHandle).getClient();
if (client == null || (client != null && !client.isConnected())) {
Toast.makeText(context, "please connect to server first",
Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(topic)) {
topic = "hello";
}
String[] topics = new String[1];
topics[0] = topic;
try {
client.subscribe(topic, 1, null, new ActionListener(context,
ActionListener.Action.SUBSCRIBE, mqttUtilsCallback,
clientHandle, topics));
} catch (MqttSecurityException e) {
Log.e(TAG, "Failed to subscribe to" + topic
+ " the client with the handle " + clientHandle, e);
} catch (MqttException e) {
Log.e(TAG, "Failed to subscribe to" + topic
+ " the client with the handle " + clientHandle, e);
}
E. 安卓開發程序已停止 大神呀 求救呀 這是什麼問題呀
03-2213:27:05.709:E/AndroidRuntime(9698):java.lang.RuntimeException:{com.example.cehualayout/com.example.cehualayout.MainActivity}:java.lang.ClassNotFoundException:Didn'tfindclass"com.example.cehualayout.MainActivity"onpath:/data/app/com.example.cehualayout-2.apk
F. android google map 開發 定位 不點擊myLocationbutton就直接實現定位
你把button的click里的代碼寫到onCreate里就可以了啊
G. 日常生活中用到的英文縮寫
1、WC 廁所
很早以前,廁所Toilet里都有水箱water closet,人們一提到water closet就想到了toilet,因此water closet就成了toilet的代名詞。後來為了方便,人們就用water closet的開頭字母W.C.來代替toilet。
WC是一種很粗俗的表達方式(相當於中國鄉村常在廁所中標「男」「女」),是英美等國一二百年前使用的,現在多使用TOILET、Bathroom、Restroom(AmE)等較文雅的詞。
2、VCD 影音光碟
VCD,影音光碟(Video Compact Disc;VCD),是一種在光碟上存儲視頻信息的標准。VCD可以在個人電腦或VCD播放器以及大部分DVD播放器中播放。VCD標准由索尼、飛利浦、JVC、松下等電器生產廠商聯合於1993年[1-2]制定,屬於數字光碟的白皮書標准。
3、APEC
亞洲太平洋經濟合作組織(Asia-Pacific Economic Cooperation,縮寫APEC),簡稱亞太經合組織,是亞太地區重要的經濟合作論壇,也是亞太地區最高級別的政府間經濟合作機制。
1989年11月5日至7日,舉行亞太經濟合作會議首屆部長級會議,標志著亞太經濟合作組織的成立。1993年6月改名為亞太經濟合作組織。1991年11月,中國以主權國家身份,中國台北和中國香港以地區經濟體名義正式加入亞太經合組織。
2001年10月,APEC會議在中國上海舉辦。這是APEC會議首次在中國舉行。2014年,APEC會議時隔13年再次來到中國。截至2014年9月,亞太經合組織共有21個正式成員和三個觀察員。
4、APP 手機軟體
手機軟體,主要指安裝在智能手機上的軟體,完善原始系統的不足與個性化。使手機完善其功能,為用戶提供更豐富的使用體驗的主要手段。
手機軟體的運行需要有相應的手機系統,目前(2017年6月1日)主要的手機系統:1.蘋果公司的iOS.2.谷歌公司的Android(安卓)系統。
5、BRT 快速公交系統
快速公交系統(BRT )作為公共交通中的一種方式,它是由快速公交車站、快速公交車、服務、營運方式、智能公交系統(ITS)等元素集成的系統。快速公交系統具有自己鮮明的特色,可以形成城市獨特的形象。
簡而言之,快速公交系統就是由人員、服務和各項相關措施集約而成的一個可以提升公交運營速度、可靠性和改善公交系統狀況的一個綜合公交運營體系。
H. android 怎樣使自己的網路請求使用虛擬mac地址
不改 回答者:匿名 5-3 12:06 網上有MAC地址的軟體,你就在網路里搜搜看看,祝你好運! 回答者:fujj - 助理 二級 5-4 15:20 可以不用改的.不知道你從那裡聽說要這樣改. 呵呵. 虛擬機網路設置有4種模式: 1:Birdged 橋接模式,該模式是相當於把你的虛擬機像一台真實主機一樣接到你的網內,和你的主機具有同等地位。而虛擬機內的操作系統上的網卡,也同樣有一個虛擬出來的MAC地址,這個MAC地址在真實網路中是真實有效的. 你在選擇這種模式的情況下,還需要以下步驟的設置: Edit(編輯)----Virtual Network settings..(修改網路屬性)----Host Virtual Network Mapping---VMnet0(注釋:把這個網卡設置選擇為你的本機的真實網卡) 2:NAT 這種模式是由安裝在你真實主機上的虛擬機程序,在你電腦上虛擬出一張名為:VMWare Network Adapter VMnet8 .的網卡,而這張網卡的作用是啟動NAT和DHPC服務. 相當於一個智能交換機,可以提供NAT數據轉換服務和DHPC服務.NAT服務主要是為你的「虛擬操作系統」和真實主機提供數據交換;DHPC服務是為你的虛擬操作系統提供自動分配IP服務(這里值得注意的是:VMnet8這張網卡的的IP是不能隨便修改的)。 從而為你的你虛擬機中安裝的的操作系統模擬出一個區域網. 3:Host-only 該模式與NAT相似,它是由虛擬在你真實主機上虛擬出來的網卡:VMWare Network Adapter VMnet1 決定的. VMnet1這張網卡同樣會提供DHPC服務為你的虛擬操作系統分配IP. 但是這種模式下的操作系統只能與你的真實主機通信,而不能聯上你家的internet.(這里我給你解釋一下,通常人們喜歡把真實主機稱為:虛擬機的「宿主」,呵呵) 所以,你在家想讓虛擬操作系統上網別選擇這個模式. 4:自定義模式. 這種模式一般是在單機上試驗復雜的網路結構而設定的. 我就不給你作詳細解釋了. 綜上所述: (1):你在家裡上網可以採用第1,第2;兩種模式.如果你使用ADSL方式我建議你使用「橋接」模式. 這樣更方便. 使用橋接模式可以把VMnet1和VMnet8這兩張網卡禁用.以免對你的虛擬操作系統產生影響. (2):我本人想強調幾點: 首先「虛擬機」與「虛擬操作系統」不能混淆; 「虛擬機」指的是在你真實主機內安裝的「虛擬機程序」 「虛擬操作系統」指的是你的「虛擬機內安裝的操作系統」 網上很多人對這個概念十分模糊,甚至有人認為:虛擬機在你真實主機上的網卡就是虛擬操作系統里的網卡. 這種想法是完全錯誤的. 其次,不要認為你在虛擬機上為所欲為都不會影響你的真實主機.因為在虛擬機內的操作,都會用到你的真實物理硬體:如物理內存,硬碟等. 如果你操作不正確,或頻繁的在虛擬機內安裝操作系統,同樣也會在你真實主機上留下很多磁碟碎片.所以操作虛擬機同樣也應該按正確的步驟進行. 最後,這篇文檔完全是現在手工打字,絕對不是在網上復制的,所以你可以考慮再給我追加20分.我說得很多,是因為想讓很多人都不必為這種簡單的問題所困擾.
I. android中遇到failed to get ged怎麼解決
failed to get的意思是未能獲得,看路徑是否添加正確,如果不正確肯定是沒有獲取到的。
J. Android怎麼實現點擊按鈕獲取當前位置的信息,沒有地圖的情況下。
1、首先,檢查那個供應商是有效的。有些在設備上可能沒效,有些可能在應用程序清單中無效。
2、如果有有效的供應商,啟動位置監聽和路由失效定時器。
3、如果從位置監聽器獲得更新,用供應的值,停止監聽器和定時器。
4、如果沒有獲得更新,並且時間已經結束,那就用最後一個已知值。
5、從有效供應商獲取最後一個已知值並且選擇最接近的。
class MyLocation{
/**
* If GPS is enabled.
* Use minimal connected satellites count.
*/
private static final int min_gps_sat_count = 5;
/**
* Iteration step time.
*/
private static final int iteration_timeout_step = 500;
LocationResult locationResult;
private Location bestLocation = null;
private Handler handler = new Handler();
private LocationManager myLocationManager;
public Context context;
private boolean gps_enabled = false;
private int counts = 0;
private int sat_count = 0;
private Runnable showTime = new Runnable() {
public void run() {
boolean stop = false;
counts++;
System.println("counts=" + counts);
//if timeout (1 min) exceeded, stop tying
if(counts > 120){
stop = true;
}
//update last best location
bestLocation = getLocation(context);
//if location is not ready or don`t exists, try again
if(bestLocation == null && gps_enabled){
System.println("BestLocation not ready, continue to wait");
handler.postDelayed(this, iteration_timeout_step);
}else{
//if best location is known, calculate if we need to continue to look for better location
//if gps is enabled and min satellites count has not been connected or min check count is smaller then 4 (2 sec)
if(stop == false && !needToStop()){
System.println("Connected " + sat_count + " sattelites. continue waiting..");
handler.postDelayed(this, iteration_timeout_step);
}else{
System.println("#########################################");
System.println("BestLocation finded return result to main. sat_count=" + sat_count);
System.println("#########################################");
// removing all updates and listeners
myLocationManager.removeUpdates(gpsLocationListener);
myLocationManager.removeUpdates(networkLocationListener);
myLocationManager.removeGpsStatusListener(gpsStatusListener);
sat_count = 0;
// send best location to locationResult
locationResult.gotLocation(bestLocation);
}
}
}
};
/**
* Determine if continue to try to find best location
*/
private Boolean needToStop(){
if(!gps_enabled){
return true;
}
else if(counts <= 4){
return false;
}
if(sat_count < min_gps_sat_count){
//if 20-25 sec and 3 satellites found then stop
if(counts >= 40 && sat_count >= 3){
return true;
}
return false;
}
}
return true;
}
/**
* Best location abstract result class
*/
public static abstract class LocationResult{
public abstract void gotLocation(Location location);
}
/**
* Initialize starting values and starting best location listeners
*
* @param Context ctx
* @param LocationResult result
*/
public void init(Context ctx, LocationResult result){
context = ctx;
locationResult = result;
myLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
gps_enabled = (Boolean) myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
bestLocation = null;
counts = 0;
// turning on location updates
myLocationManager.requestLocationUpdates("network", 0, 0, networkLocationListener);
myLocationManager.requestLocationUpdates("gps", 0, 0, gpsLocationListener);
myLocationManager.addGpsStatusListener(gpsStatusListener);
// starting best location finder loop
handler.postDelayed(showTime, iteration_timeout_step);
}
/**
* GpsStatus listener. OnChainged counts connected satellites count.
*/
public final GpsStatus.Listener gpsStatusListener = new GpsStatus.Listener() {
public void onGpsStatusChanged(int event) {
if(event == GpsStatus.GPS_EVENT_SATELLITE_STATUS){
try {
// Check number of satellites in list to determine fix state
GpsStatus status = myLocationManager.getGpsStatus(null);
Iterable<GpsSatellite>satellites = status.getSatellites();
sat_count = 0;
Iterator<GpsSatellite>satI = satellites.iterator();
while(satI.hasNext()) {
GpsSatellite satellite = satI.next();
System.println("Satellite: snr=" + satellite.getSnr() + ", elevation=" + satellite.getElevation());
sat_count++;
}
} catch (Exception e) {
e.printStackTrace();
sat_count = min_gps_sat_count + 1;
}
System.println("#### sat_count = " + sat_count);
}
}
};
/**
* Gps location listener.
*/
public final LocationListener gpsLocationListener = new LocationListener(){
@Override
public void onLocationChanged(Location location){
}
public void onProviderDisabled(String provider){}
public void onProviderEnabled(String provider){}
public void onStatusChanged(String provider, int status, Bundle extras){}
};
/**
* Network location listener.
*/
public final LocationListener networkLocationListener = new LocationListener(){
@Override
public void onLocationChanged(Location location){
}
public void onProviderDisabled(String provider){}
public void onProviderEnabled(String provider){}
public void onStatusChanged(String provider, int status, Bundle extras){}
};
/**
* Returns best location using LocationManager.getBestProvider()
*
* @param context
* @return Location|null
*/
public static Location getLocation(Context context){
System.println("getLocation()");
// fetch last known location and update it
try {
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
String strLocationProvider = lm.getBestProvider(criteria, true);
System.println("strLocationProvider=" + strLocationProvider);
Location location = lm.getLastKnownLocation(strLocationProvider);
if(location != null){
return location;
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}