MasterofProject

[Android] imitation 360 mobile guards simple design ideas and source code

3975 people read comment(10) Collection Report
Classification:

         I have recently been busy over the Guangzhou run, so difficult to find hard to find good practice, blog is a bit long not to update. The goal of imitation 360 mobile guards more is out of common knowledge in a consolidated, more suitable for like the contact did not take long for the learners in learning brought practiced hand to keep writing code of the feeling of a good small projects.


      Involved technology:

     Are very commonly used in Android development, but it involves a wide range of it. (on the small side nothing new, a few small examples, forgive me forgive me! ~) but also for practiced hand to say, in the writing of this project is also used more controls, sometimes a problem also used the different methods: for example in the server parses the XML file used JSON data analysis in general, also used the gson data analytic number according to (it is said that this gson is currently being used by most companies, Xiaobian whether points out, ha ha); listview pattern is more, in addition to conventional listview +viewholder small optimization ideas, in some places is also used a single category fixed head listview; in some places also use listview custom implementation side pull removed. At the same time, it can listview item to add animation to increase the visual effect. In addition, when the listview data is loaded, it can be a traditional loading, there are also used in batch loading, paging load. (ha ha, or pretty fun) other details if you are interested, directly into the code and underestimate a lot of good, of course, is also used many animation and custom controls, Xiaobian introduce the function of the various parts of the following will be little mention.


      Function is described as follows:

Article is limited, small series here is not a list of code...

      

    1, mobile phone security

       Function description:In the main interface, click on the phone security button, pop-up password input box (if for the first time to enter the pop-up settings password box interface), the password stored byMD5Encrypted after storageSharePreference, after verifying the password in the jump to mobile phone anti-theft page (if it can not to set security information will jump to mobile security settings pages), it first mobile security settings page, set the security number, bindingSimCard, and whether to open the security settings. Mobile phone security page in the face of these information to display and provide users to modify the button.Anti theft function: (OneBoot monitor mobile phoneSimCard changes, if the change to the security number to send a reminder message;Two) in the lost mobile phone through SMS remote control: the stolen mobile phone cleaning data, positioning mobile phone stolen, stolen phone lock screen screen saver settings and control the stolen mobile phone broadcast music alarm.


  Technology realization:(1)TestingSimCard change: in the mobile phone security Page MonitorSimThe card button changes if the button is turned on if the phone is burglar andSimCard button boot case, boot broadcastBootCompleteReceiverWill get the current phoneSimCard number, and the original saveSimCard number for comparison (throughTelephonyManagerAnd, if not the same, passSmsManagerObject and security number to send text messages. (2)Mobile positioning, mobile phone data cleaning, anti-theft mobile phone and mobile phone alarm music playback: via SMS monitor the broadcast, by acquiring the short message content to and originally set a good password awakened comparison, data cleaning and a key lock screen via the device managerDevicePolicyManagerAchieve, mobile phone positioning through aServiceMonitor position change. (3)Select the phone number from the phone contact: the equivalent of reading and writing the phone's built-in database.

  

  Partial function display:



  2, communication guards

Function description:(1)Add black list (in two ways: input by the input box; and by calling the phone contact mode); (2)Query black list;3)To intercept the short message and the phone in the black list.


   Technology realization:(1) add black list: the establishment of a database table, the package, the black list numbers stored in the database.(2) query blacklist: because there is no suitable database to find, so the blacklist database with just established a blacklist database to replace, query database.(3) SMS and telephone intercept: (this function is set up in the settings, the default is the open state).-That is directly inSplashPage directly on the black list of services, through the event managerActivityManagerGets the service that is running in the background, to determine whether the black list service has been turned on.OneTelephone interception: by telephone ManagerTeleponyManagerMonitor mobile phone status, access to the phone number, query the database, if the black list database in the presence of the number, the system through the reflective way to intercept telephone intercept telephone calls, and throughContentProviderWay to delete incoming calls from a telephone record;TwoSMS interception: the service in the dynamic registration of radio, throughSmsManagerObject back to the text messages, the number of query database, callAbortBroadcastTo intercept text messages.


 Partial function display:



 3, software management

  Function description:Get the application of the system installed, classified into mobile applications and system applications throughListviewDisplay. By clicking on each of the purposes of the application for the application of the operation: running, unloading, sharing and detailed information.


  Technology realization(:1)To obtain the application of mobile phone security: through the system provided by the package manager to obtain the application information, (2)Operation, unloading, sharing, and detailed information.StartAcitvity() jump to the correspondingActivityOperation.


 Partial function display:



 4, process management

   Function description:Gets the details of the application being run by the system, and displays theListviewIn. And for the user to select a single entry of the cleaning process or all clean up.


   Technology realizationThrough the package managerPackageManagerAnd task manager to obtain detailed information about the process that the system is running.ListviewShow (side cleaning individual process, a key clean except oneself in the process), clean up the main callKillbackgroupprocessMethod


   Partial function display:



 5, mobile antivirus

   Function descriptionScan the phone in the application, if the virus is found to deal with the virus to deal with the page for the user to choose whether or not clear.


   Technology realizationThe package manager through the system.PackageManagerGets the application package name and the name of the package.MD5Processing, with the database in theMD5Virus nameMD5Contrast (applications in mobile phonesApkForm of existence. If the virus to jump to the application of the uninstall interface for users to clean up.


   Partial function display:



 6, telephone attribution query

   Function description(1), telephone home inquiry.2)And to the home to show


   Technology realization(:OneTelephone inquiries: and database related operations, small projects with more than what the package is almost;TwoCall home display: display: CustomWindowManagerDisplay customView, to listen to the caller: define an incoming callService, listen to the phone state to obtain the phone number, call the database query the number of home, and it is displayed in theViewThe attribution style: (very simple, a few background); the location of the home settings (through)OntoucheventMonitor the position of the contact point, get the coordinates of the moving point.Onlayout OnDraw onmeasure (On these three processes)But need to pay attention to.ActivityMiddle and heavy paintingWindowManagerThere is a difference between the detailed comparison of the code piece there are more detailed notes seeAddressServiceas well asDragViewActivity).


         Partial function display:




   7, Cheng Xusuo

       Function description:For all applications of the system for the user to choose to add a lock and to be locked program password protection


       Technology realization:(OneHas been added with the application and the application of the stomach lock application display: through twoFragmengt, users click on the lock or no lockFragmentTheItem listviewdeAdd and delete operations to the application package name. (Two) to lock password protected program: a watchdog process in the service, have been monitoring application task stack in the first application, if the first application exists in a protected database application in jump to the password input interface.


   Existing problems:The current side of the jump interface has not been achieved, the problem is likely to be the location of the problem need to be further investigation.


The basic function of the show to this, there are many bug, this period of time is relatively busy, bug progress is relatively slow. And the work done in BaseActivity is very simple: to monitor gesture sliding, the code is also very simple to look directly at the code:

Abstract class BaseActivity extends Activity{public
GestureDetector gestureDetector private;
SharedPreferences mPrefs public;

@Override
Void onCreate protected (savedInstanceState Bundle) {
Super.onCreate (savedInstanceState);

MPrefs = getSharedPreferences ("config", MODE_PRIVATE);

GestureDetector = GestureDetector new (this, GestureDetector.SimpleOnGestureListener new) {
@Override
Boolean onFling public (E1 MotionEvent, E2 MotionEvent, velocityX float, velocityY float,) {
If (e1.getRawX () - e2.getRawX () > 200) {
ShowNextPage ();
True return;
If}else (e2.getRawX () - e1.getRawX () > 200)
{
ShowPreviousPage ();
True return;
}
Super.onFling return (E1, E2, velocityX, velocityY);
}
});
}

Abstract void showPreviousPage protected ();

Abstract void showNextPage protected ();

@Override
Boolean onTouchEvent public (event MotionEvent) {
GestureDetector.onTouchEvent (event); / / principal gesture recognition processing touch events
Super.onTouchEvent return (event);
}
}

Splash screen initialization: when the user first downloads, external database copy to mobile phone users SD card directory to determine an updated version, judge whether to create a shortcut on the desktop and start stop service and so on, or direct look at the code it:

Class SpashActivity extends AppCompatActivity public {
Static final int CODE_UPDATE_DIALOG protected = 0;
Static final int CODE_URL_ERROR protected = 1;
Static final int CODE_NET_ERROR protected = 2;
Static final int CODE_JSON_ERROR protected = 3;
Protected static final int CODE_ENTER_HOME = 4; / / to enter the main page

TextView tvVersion private;
RelativeLayout rlRoot private;

/ / information returned by the server.
Private String mVersionName; / / version name
Private int mVersionCode; / / version number
Private String mDesc; / / Version Description
Private String mDownloadUrl; / / download address

Handler mHandler new = Handler private () {
Void handleMessage public (MSG android.os.Message) {
Switch (msg.what) {
CODE_UPDATE_DIALOG: case
ShowUpdateDailog ();
Break;
CODE_URL_ERROR: case
Toast.makeText (SpashActivity.this, "URL error", Toast.LENGTH_SHORT)
.show ();
EnterHome ();
Break;
CODE_NET_ERROR: case
Toast.makeText (SpashActivity.this, "network error", Toast.LENGTH_SHORT)
.show ();
EnterHome ();
Break;
CODE_JSON_ERROR: case
Toast.makeText (SpashActivity.this, "data parsing error",
.show (Toast.LENGTH_SHORT) ();
EnterHome ();
Break;
CODE_ENTER_HOME: case
EnterHome ();
Break;

Default:
Break;
}
};
};

@Override
Void onCreate protected (savedInstanceState Bundle) {
Super.onCreate (savedInstanceState);
SetContentView (R.layout.activity_spash);

CopyDB ("address.db"); / / copy attribution query database

Copy the directory / asset database file virus
CopyDB ("antivirus.db");

StartService (Intent new (this, CallSafeService.class));

WatchDogIntent //Intent = Intent new (this, WatchDogService.class);
//startService (watchDogIntent);

InitView ();
OpEvents ();
CheckVersion ();
}

Void opEvents private () {
TvVersion.setText ("version Name:" + getVersionName ());

alphaanimation alphaanimation =新alphaanimation(0.3f,1F);
alphaanimation setDuration(2000);
rlroot startanimation(alphaanimation);
}

private String getversionname() {
getpackagemanager() PackageManager PackageManager =;
尝试{
packageInfo packageInfo = PackageManager.得到自己的包名(
getpackagename(),0);
字符串packageinfo.versionname versionName =;
返回versionName;
} catch(packagemanager.namenotfoundexception e){
E. printstacktrace();
}
返回“”;
}

* * * *
*获取本地APP的版本号
*
* @返回
*
私有getversioncode() {
getpackagemanager() PackageManager PackageManager =;
尝试{
packageInfo packageInfo = PackageManager.得到自己的包名(
getpackagename(),0);//获取包的信息

国际versioncode = packageinfo.versioncode;
返回versioncode;
} catch(packagemanager.namenotfoundexception e){
/ /没有找到包名的时候会走此异常
E. printstacktrace();
}

返回- 1;
}

initview() { private void
tvversion =(TextView)findViewById(r.id.tv_version);
rlroot =(RelativeLayout)findViewById(r.id.rl_root);
}

checkversion() { private void
最后长时间currenttimemillis() =系统;
/ /启动子线程异步加载数据
新的thread() {

“重写”
run() { public void
消息obtain() =消息;
你conn = null;
尝试{
/ /本机地址用localhost,但是如果用模拟器加载本机的地址时,可以用IP(10.0.2.2)来替换
URL =新的URL(“HTTP:/ / 10.0.2.2:8080 /更新。JSON”);
conn =(你)openconnection() URL;
conn.setrequestmethod(“”);/ /设置请求方法
conn.setconnecttimeout(5000);//设置连接超时
conn.setreadtimeout(5000);//设置响应超时,连接上了,但服务器迟迟不给响应
康涅狄格州connect();/ /连接服务器

中断响应代码=康涅狄格州getresponsecode();/ /获取响应码
如果(响应代码= = 200){
输入流InputStream =康涅狄格州getinputstream();
结果字符串= streamutils ReadFromStream(InputStream);
/ /系统。出来。println(“网络返回:”+结果);

/ /解析JSON
JSONObject乔=新的JSONObject(结果);
mversionname =乔GetString(“versionName”);
mversioncode =乔。getInt(“versioncode”);
麦克唐纳·道格拉斯电子系统公司=乔GetString(“说明”);
mdownloadurl =乔GetString(“downloadurl”);
/ /系统。出来。println(“版本描述:”+麦克唐纳·道格拉斯电子系统公司);

如果(mversioncode > getversioncode()){ //判断是否有更新
/ /服务器的versioncode大于本地的versioncode
/ /说明有更新,弹出升级对话框
msg.what = code_update_dialog;
{ }
/ /没有版本更新
msg.what = code_enter_home;
}
}
} catch(malformedurlexception e){
错误的异常/网址
msg.what = code_url_error;
E. printstacktrace();
} catch(IOException e){
/ /网络错误异常
msg.what = code_net_error;
E. printstacktrace();
} catch(jsonexception e){
/ / JSON解析失败
msg.what = code_json_error;
e.printstacktrace();
最后,{ }
system.currenttimemillis endtime =(长);
龙timeused endtime - starttime=;//访问网络花费的时间
{ if(timeused<2000)
//强制休眠一段时间,保证闪屏页展示2秒钟
try {
thread.sleep(2000年timeused);
{}catch(interruptedexception)
e.printstacktrace();
}
}

mhandler.sendmessage(MSG);
if(Conn的!=null){
conn.disconnect();//关闭网络连接
}
}
}
.start();}
}

××××××××××××××号
×××××××升级对话框
*/
保护showupdatedailog(){ void
alertdialog =新alertdialog.builder生成器生成器。(本);
builder.settitle(“+ mversionname最新版本:”);
builder.setmessage(mdesc);
builder.setcancelable(false);/ / / /不让用户取消对话框,用户体验太差,尽量不要用
builder.setpositivebutton(“立即更新”,《dialoginterface.onclicklistener(){

@Override
public void onClick(dialoginterface对话框,其中{ int)
System.out.println(“立即更新”);
(下载);
}
});

builder.setnegativebutton(“以后再说”,《dialoginterface.onclicklistener(){

@Override
public void onClick(dialoginterface对话框,其中{ int)
enterhome();
}
});

//设置取消的监听,用户点击返回键时会触发
builder.setoncancellistener(新dialoginterface.oncancellistener(){

@Override
public void { oncancel(dialoginterface对话框)
enterhome();
}
});

builder.show();
}

××××××××××××××号
×××××××下载apk文件
*/
无效的下载受保护(){
if((()))).equals environment.getexternalstoragestate
environment.media _安装)){

/ / / / tvprogress.setvisibility(view.visible显示进度);

environment.getexternalstoragedirectory目标=(字符串)
+“/ update.apk”;
//xutils
httputils =新httputils(工具);
新的目标,utils.download(mdownloadurl,requestcallback <文件>(){

//下载文件的进度
@Override
公共无效的加载的总电流(龙,龙,
布尔isuploading){
super.onloading(总电流,isuploading);
//System.out.println(“下载进度:“+”/“+ +电流的总和);
tvprogress.settext(“下载进度/“+ +”,总电流×100(%);
}

//下载成功
@Override
公共无效(responseinfo <文件> onsuccess arg0){
System.out.println(“下载成功”);
//跳转到系统下载页面
意图和意图(意图intent.action =新_视图);
intent.addcategory(intent.category _默认);
intent.setdataandtype(uri.fromfile(arg0.result)
“应用程序/ vnd.android.package-archive”);
startactivity(意图);//
startactivityforresult(米,0);//如果用户取消安装的话,
//会返回结果,回调方法onactivityresult
}

//下载失败
@Override
公共无效填充(String arg0 httpexception,arg1){
toast.maketext(spashactivity.this,“下载失败!”,
toast.length _);.show(短)
}
});
} else {
toast.maketext(spashactivity.this,“没有找到sdcard!”,
烤面包。length_short show());
}
}

/ /如果用户取消安装的话,回调此方法
“重写”
protected void onActivityResult(int,int requestCode,ResultCode,意图数据){
enterhome();
超。onActivityResult(requestCode,ResultCode,数据);
}

* * * *
*进入主页面
*
enterhome() { private void
意图意图=新的意图(这homeactivity。类);
startActivity(意图);
finish();
}

* * * *
*拷贝数据库
*
* @param dbname
*
private void copydb(字符串dbname){
文件filesdir = getfilesdir();
系统的输入(“路径:“+ filesdir。getabsolutepath());
文件destfile =新的文件(getfilesdir(),dbname);/ /要拷贝的目标地址

如果(destfile。exists()){
系统的输入(“数据库”+在+“已存在!”);
返回;
}

FileOutputStream = null;
= null字节输入流;

尝试{
/ = getassets()开放(北京);
在getclassloader()。getresourceasstream(“资产/”+ dbname);
在available() int length =;
/ /系统。出来。println(“数据库大小”+长);
=新FileOutputStream(destfile);

int len = 0;
字节[ ]缓冲=新的字节[ 1024 ];

而((len =在读(缓冲区))!= - 1){
写出来。(缓冲区,0,Len);
}

} catch(IOException e){
E. printstacktrace();
最后{
尝试{
在();
出来。();
(例外情况){
E. printstacktrace();
}
}
}
}

 


   源码下载地址360手机卫士简易实现版仿

    GitHub免积分源码下载地址:GitHub源码

猜你在找
查看评论
*以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场