手機安全衛士第三天實現的功能:
1.嚮導頁的手勢滑動。
2.首次繫結sim卡,並在重啟的時候效驗sim卡序列號是否相同。
3.為傳送進來的簡訊做乙個廣播監聽,監聽簡訊號碼和內容。把號碼和安全號碼進行對比,內容和特殊指令進行對比。
首先嚮導頁手勢滑動功能的實現
嚮導頁手勢滑動用到了乙個genturedetector類,在使用genturedetector只需要在new的時候傳入監聽手勢滑動時間即可,但是new的genturedetector類要放在空間的ontouch中驚醒呼叫,使用方法如下。
private gesturedetector mdetector;
mdetector = new gesturedetector(this, new gesturedetector.******ongesturelistener()
// 判斷滑動是否過慢
if (math.abs(velocityx)<100)
if (e1.getrawx() - e2.getrawx() > 200)
if (e2.getrawx() - e1.getrawx() > 200)
return super.onfling(e1, e2, velocityx, velocityy);
}});
}public void next(view view)
public void previous(view view)
public abstract void showpreviouspage();
public abstract void shownextpage() ;
@override
public boolean ontouchevent(motionevent event)
},並與該自定義控制項進行了互動。用來判斷按下去是否已經繫結了sim卡。
private settingitemview sivsim;
sivsim = (settingitemview) findviewbyid(r.id.siv_sim);
string sim = mpref.getstring("sim", null);
if (!textutils.isempty(sim))else
sivsim.setonclicklistener(new view.onclicklistener() else
}});
在這裡預設是沒有繫結sim卡的,然後在這裡加乙個判斷,
如果使用者沒有加入sim卡,則不允許使用者進入第三個嚮導頁。
@override
public void shownextpage()
startactivity(new intent(this,setup3activity.class));
finish();
// 兩個介面切換的動畫, 進入動畫和退出動畫
overridependingtransition(r.anim.tran_in,r.anim.tran_out);
}
然後增加乙個開機廣播,用來監聽繫結的sim序列號和啟動時的序列號是否相同,如果相同,不做任何操作,如果不同,傳送一條簡訊給安全號碼;
/**
* 監聽手機開機啟動的廣播
* created by administrator on 2016/4/28.
*/public class bootcompletereceiver extends broadcastreceiver else }}
}}
然後為傳送進來的簡訊增加乙個廣播用來判斷是否輸入了特殊指令。
//拿到簡訊包
object objects = (object) intent.getextras().get("pdus");
for (object object:objects) else if("#*location*#".equals(messagebody))else if ("#*wipedata*#".equals(messagebody)) else if ("#*lockscreen*#".equals(messagebody))
要獲取地理位置有三種辦法:網路定位,基站定位,和gps定位優缺點分別如下。
在真實的機器上應該是使用最好的乙個定位技術,使用
getbestprovider(criteria, true);// 獲取最佳位置提供者
獲取地理位置這裡建立乙個服務然後把經緯度寫在sharedpreferences中
/**
* 獲取經緯度座標的service
* created by administrator on 2016/4/30.
*/public class locationservice extends service
@nullable
@override
public ibinder onbind(intent intent)
class mylocationlistener implements locationlistener
//位置提供者狀態發生變化
@override
public void onstatuschanged(string provider, int status, bundle extras)
//開啟手機定義服務
@override
public void onproviderenabled(string provider)
//關閉手機定位服務
@override
public void onproviderdisabled(string provider)
}@targetapi(build.version_codes.m)
@override
public void ondestroy()
}
手機安全衛士(三) 工具類
前兩篇部落格都是將一些前期的規劃,實現哪些需求,而這篇部落格主要講一下在手機安全衛士開發中可能用的一些工具類!這也是非常重要的東,可以說是一勞永逸的工作!在我們實際開發中,我們常需要獲取應用的一些資訊來使用,比如獲取應用程式基本資訊 獲取permission是否註冊等。這些資訊獲取都借助於andro...
手機安全衛士開發系列(2) splash介面
1 activity主要用來頁面的展示 2 engine包 獲取資料和展示資料 包含資料介面卡 3 domain包 存放資料實體 利用程式的業務邏輯進行 劃分,比如qq,qq有登陸模組,聊天模組,群組模組,qq空間模組 com.tencent.login com.tencent.im com.ten...
百天打卡第三天 執行緒安全
程式死鎖的基本原因 下面這三句話背下來面試很受用synchronize 關鍵字可以對 塊或方法進行修飾,而不能夠對於class以及變數進行修飾。接下來的部分也背下來吧,蠻有用的 1與monitor 關聯的物件不能為空 錯誤程式 private final object mutex null publ...