版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
防盜功能:銷毀數(shù)據(jù),鎖屏,警報,SIM卡變更,GPS追通訊衛(wèi)士:來電和的管軟件管理:應(yīng)用的列表展示,應(yīng)用的卸載,運行與流量管理:顯示所有應(yīng)用的上傳和流進程管理:顯示所有運行進程列表和內(nèi)存占用大小,緩存清理:高級工具:歸屬地查詢,備份與還原,程序鎖和常 查設(shè)置中心:歸屬地服務(wù),歸屬地顯示風(fēng)格,歸屬地顯示位置,程序鎖服殺毒:對中安裝的所有應(yīng)用進行查殺,發(fā)現(xiàn)應(yīng)用進行卸功能一:1.Activitytheme,2.3.<rotate>,4.5.顯示透明,縮放,6.assertdbAssertManager,7.8.聯(lián)網(wǎng)請求服務(wù)器數(shù)URL,HttpUrlConnection/Http9.xml/jsonXmlPull和JSONObject或Thread+Environment,12.聯(lián)網(wǎng)狀功能二:GridView,自定義名稱的顯示設(shè)置與登陸界自定義內(nèi)容布局的的加MD5KeyEvent處理功能四:防盜的設(shè)<RelativeLayout>,<style>,<translate>,綁定當(dāng)前中的SIMephonyManager,SharedPreference,顯示聯(lián)系人列pter,ProgressDialog,Handler,startActivityForResult(),DeviceManager,BroadcastReceiver及配置命令實現(xiàn)gps追蹤,數(shù)據(jù)銷毀,遠BroadcastReceivere及配置,功能五:歸屬地查詢與來電顯加載歸屬地數(shù)據(jù)庫文流程分析, k,查詢歸屬APIDemo動畫效果,AlertDialog,功能六:OpenHelper,DataBaseListActivity,ArrayAdapterContext,Service,AIDL掛 BroadcastReceiver功能七: BaseAdapter,PopupWindow,功能八:應(yīng)用的列表顯示Database,ContentProvider,ContentResolver,ContentObsver,Service,功能九:顯示系統(tǒng)和第應(yīng)用進程列PackageManager,Asynk,ListView,BaseAdapter,RemoteView,Service,PendingIntent,功能十:PackageManager,反射調(diào)用@hide的方法功能十一:SlidingDrawer,ResolveInfo,功能十二:常用號查AssetManager,Database, 備份中的所有數(shù)ContentResolver,Uri,GsonSD還原備份的數(shù)同上,功能十三:殺理解與殺毒軟計算機viewgroup.addView(view掃描應(yīng)用拷貝包含數(shù)據(jù)的db文異步查找,同步顯示進度: 卸載帶應(yīng)功能一:歡迎界面及版本更新檢查(難在創(chuàng)建一個新的應(yīng)用時,就需要對整個應(yīng)用的包結(jié)構(gòu)進行一個設(shè)計,對應(yīng)用包的組織大致有方式二:按類型來組織代碼的包結(jié)構(gòu),衛(wèi)士衛(wèi)士 android:text="版本號:1.0"<rotate<rotate android:android:indeterminateDrawable="@anim/anim_loding_progress"http://"http://AlphaAnimationAlphaAnimationanimation=newAlphaAnimation(0.0f,1.0f);PackageManagerPackageManagerpackageManager=PackageInfopackageInfo=packageManager.getPackageInfo(context.getPackageName(),Stringversion=動態(tài)編碼的方式<stylename="AppTheme"<itemname="android:windowNoTitle">true</item把 @paramprivatevoidcopyDB(Stringdbname)Filefile=newLog.iTAGdbname+"數(shù)據(jù)庫已經(jīng)存在,不需要拷貝了tryInputStreamis=FileOutputStreamfos=newintlen=bytebuffer[]=newbyte[1024];while((len=is.read(buffer))!=-1){fos.write(buffer,0,}}catch(IOExceptione){}}}*publicstaticbooleanisNetConnected(Contextcontext){booleanconnected=false;//獲 ConnectivityManagermanager=(ConnectivityManager)獲取active的NetworkInfoNetworkInfonetworkInfo=if(networkInfo!=null)connected=}return}<?xmlversion="1.0"<?xmlversion="1.0"encoding="UTF-<desc>解決了上一個版本中的不少bug優(yōu)化了網(wǎng)絡(luò)請求邏輯{{desc:"解決了上一個版本中的不少bug,優(yōu)化了網(wǎng)絡(luò)請求邏輯}}URLurl=new//HttpURLConnectionconnection=(HttpURLConnection) 返回的數(shù) InputStreamis=XmlPullxmlprivateprivateUpdateInfopar ml(InputStreamis)throwsException{UpdateInfoinfo=newUpdateInfo();XmlPullParserpullParserpullParser.setInput(is,"utf-8");inteventType=while(eventType!=XmlPullParser.END_)if(eventType==XmlPullParser.START_TAG){StringtagName=pullParser.getName();if("version".equals(tagName)){}elseif("apkUrl".equals(tagName)){}elseif("desc".equals(tagName)){}}eventType=}return}JsonObjectjsonprivateprivateUpdateInfoparseJson(InputStreamis)throwsExceptionStringjsonString=Utils.readString(is);JSONObjectobject=newJSONObject(jsonString);UpdateInfoinfo=newUpdateInfo();return}UpdateInfo=newGson().fromJson(jsonString,newprivateHandlerhandler=newHandler()publicvoidhandleMessage(android.os.Messagemsg)switch(msg.what)casecasecasecase}}newThread(newRunnable()publicvoidrun()tryinfo=}catch(Exceptione){}}提示去和顯示進*顯示diaogprivatevoidshowDownloadDialog()newAlertDialog.Builder(this)ddd.setTitle("版本更新.setMessage("有更新的版本,是否立 更新publicvoidonClick(DialogInterfacedialog,intwhich){}}).setNegativeButton("取消new",newDialogInterface.OnClickListener(){publicvoidonClick(DialogInterfacedialog,intwhich){}}*開啟分線 apk,并進行安裝更privatevoidstartDownloadApk() finalStringapkUrl= newThread(newRunnable(){publicvoidrun()try.downloadAPK(apkUrl,apkFile,}catch(Exceptione){}}}apksd卡中FileFilesdFile=Environment.getExternalStorageDirectory();apkFile=newFile(sdFile,"update.apk");FilefilesDir=apkFile=newFile(filesDir,Intentintent=Intentintent=newIntent();<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE" wifi<uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE"<uses-permission<uses-permissionandroid:name="android.permission.INTERNET"sd<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"功能二:privatestaticprivatestaticfinalString[]NAMES=newString[] 防盜通訊衛(wèi)士軟件管理流量管理進程管理 殺毒緩存清理高級工具設(shè)置中心privatestaticfinalint[]ICONS=newint[]{R.drawable.widget01,R.drawable.widget02,R.drawable.widget03,R.drawable.widget04,R.drawable.widget05,R.drawable.widget06,R.drawable.widget07,R.drawable.widget08,R.drawable.widget09};<?xmlversion="1.0"encoding="utf-<LinearLayoutxmlns:android="http://s publicpublicViewgetView(intposition,ViewconvertView,ViewGroupparent)if(convertView==null)convertView=inflater.inflate(R.layout.main_item,}ImageViewimageView=(ImageView)convertView.findViewById(R.id.iv_item_main_icon);TextViewtextView=(TextView)convertView.findViewById(R.id.tv_item_main_name);return}finalfinalEditTexteditTextnewEditText(this);new.setPositiveButton("確定newDialogInterface.OnClickListenerpublicvoidonClick(DialogInterfacedialog,intwhich)}}).setNegativeButton("取消Editoredit=preferences.edit().putString("lost_name", StringlostName=preferences.getString("lost_name",是否設(shè)置過的判<LinearLayout<LinearLayoutandroid:orientation="vertical"> android:textSize="18sp" android:inputType="textPassword"/> android:inputType="textPassword"/>"android:text="取消"/><LinearLayout<LinearLayoutandroid:orientation="vertical">android:text="登陸"android:textSize="18sp" android:inputType="textPassword"/>android:text="確定"/>android:text="取消"/>9patch的制指定patch區(qū)域(可區(qū)域<selector<selector<item/apk/res/android"面<itemSelector連續(xù)點擊回退鍵,backupprivatebooleanexitprivatebooleanexitfalse只有它為trueprivateHandlerhandler=newHandler(newHandler.Callback(){publicbooleanhandleMessage(Messagemsg)if(msg.what==1)Log.e("TAG2s內(nèi)沒有再點exitfalse;//2s內(nèi)沒有再點back下次點back}return}publicbooleanonKeyUp(intkeyCode,KeyEventevent)if(keyCode==KeyEvent.KEYCODE_BACK)if(!exit)exittrue;//標(biāo)識再點一次backhandler.sendEmptyMessageDelayed(1,handler.sendEmptyMessageDelayed(1,return}else}}returnsuper.onKeyUp(keyCode,}對進行MD5加對于應(yīng)用中保存的,需要做加理再保存起來,這樣就不至于將用項目中用得最多的一種:MD5加 密MD532位的字符串,將得到的數(shù)值轉(zhuǎn)換為16進制的字符串如果它只有一位在它的前面補1616進制形式的字符串連接起來它就是md532publicstaticStringmd5(Stringpwd){StringBuffersb=newStringBuffer();try{MessageDigestdigest=byte[]bytes=digest.digest(pwd.getBytes("utf-for(bytebbytesintnumberb&255;//也可以&//轉(zhuǎn)化為16進制形式的字符串不足2位前面補StringnumberString=if(numberString.length()==1){numberString=0+numberString;}}}catch(Exceptione){}returnreturn}功能三:防盜與設(shè)置(難關(guān)鍵:<style>,<shape>,<RelativeLayout>,<<LinearLayout<LinearLayoutandroid:orientation="vertical">android:text="1.歡迎使 防盜 防盜衛(wèi)士:"android:textSize="20sp"/> <!—<style<item<item<item<item<item<item防盜設(shè)置界面"下一步"<style<item<item<item<item<item防盜設(shè)置界面"上一步"<style<item<item<item<item<item<shape<shapeandroid:shape="rectangle"android:color="#ffbc04e5"/><translate<translateandroid:duration="400">綁定當(dāng)前中的SIM關(guān)鍵技術(shù) publicpublicstaticStringgetSimNumber(Contextcontext) ephonyManager= } Handler,Thread*publicList<ContactInfo>getContactInfos(){List<ContactInfo>list=newArrayList<ContactInfo>();ContentResolverresolver=String[]projection={ Y_NAME,Phone.NUMBERCursorCursorcursor=resolver.query(Phone.CONTENT_URI,projection,null,null,while(cursor.moveToNext())Stringname=cursor.getString(0);Stringnumber=cursor.getString(1);list.add(newContactInfo(name,number));}return}關(guān)鍵技術(shù) protectedprotectedvoidonActivityResult(int{ode,intresultCode,Intent ode==REQ_CONTACT_CODE&&resultCode==2)//顯示選擇 Stringnumber=data.getStringExtra("number");}}關(guān)鍵技術(shù) publicpublicpleteReceiverextendsBroadcastReceiverpublicvoidonReceive(Contextcontext,Intentintent)條件1booleanisProtected=SpUtils.getInstance(context).getBoolean(SpUtils.IS_PROTECTED,false);if(!isProtected)//條件2:當(dāng) StringcurrSimNumber=StringsimNumber=SpUtils.getInstance(context).getString(SpUtils.SIM,null);if(simNumber!=null&&simNumber.equals(currSimNumber))//發(fā)送一個提 StringStringnumber=SpUtils.getInstance(context).getString(SpUtils.NUMBER,null);Log.e("TAG","number="+number);if(!Utils.isEmpty(number))SmsManagersmsManager=SmsManager.getDefault();smsManager.sendTextMessage(number,null," 了!",null,null);}}}<receiver<receiver<action PLETED"命令實現(xiàn)gps追蹤,數(shù)據(jù)銷毀,鎖屏,功 publicclassSmsReceiverextendspublicclassSmsReceiverextendsBroadcastReceiver{publicvoidonReceive(Contextcontext,Intentintent){Bundlebundle=intent.getExtras();Object[]pdus=(Object[])byte[]pdu=(byte[])SmsMessagesmsMessage=StringphoneNumber=smsMessage.getOriginatingAddress();Stringmessage=smsMessage.getMessageBody();if("#location#".equals(messagegps追蹤Log.e("TAG","回送位置信息!");GpsUtils.sendLocation(context,safeNumber);}elseif("#reset#".equals(message)){// Log.e("TAG"," elseif("#lock#".equals(message Log.e("TAG <receiver<receiver<intent-filter<action ephony.SMS_RECEIVED"publicstaticvoidresetPhone(Contextcontext) Managermanager=}elseif("#alarm#".equals(message Log.e("TAG"," Utils.runAlarm(context,}}}publicstaticpublicstaticvoidlockScreen(Contextcontext) Managermanager=(Device manager.resetPassword("23456",0);//重新設(shè)置}publicpublicstaticvoidrunAlarm(Contextcontext,intresourceId) yermedia yer=Media yer.create(contextresourceId); yer.setVolume(1.0f,1.0f);//設(shè)置最大音量 }三種定位方式:基于(gps),基于網(wǎng)絡(luò)(network),基基于:定位慢,準確度高,受基于網(wǎng)絡(luò):定位快,準確度低,受小,但必須聯(lián)基于:誤差與數(shù)量與遠近有publicpublicvoidsendLocation(Contextcontext,Stringnumber)thisthis.safeNumber=lm=(LocationManager)if(!lm.isProviderEnabled(LocationManager.GPS_PROVIDERMSUtils.showMsg(context,"GPS沒有開啟");}Locationlocation=if(location!=null)doublelongitude=doublelatitude=Stringresult="經(jīng)度:"+longitude+",緯度:"+latitude;Log.e("TAG","發(fā)送 :"+result);SmsManager.getDefault().sendTextMessage(number,null,result,null,}//////參數(shù)備注:參數(shù)2和3,如果參數(shù)3不為0,則以參數(shù)3為準;參數(shù)3為0,則通過時間來定時更新;兩lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,10000,1,}關(guān)鍵技術(shù) 對于第應(yīng)用,如果需要做鎖屏,恢復(fù)出廠設(shè)置等操作,需要提前先激活當(dāng)前應(yīng)用的、強制清除,修改、設(shè)置屏幕燈光漸暗時間間隔等操作。android:permission=android:permission="android.permission.BIND_DEVICE_ADMIN">android:resource="@xml/my_admin"/><actionandroid:name="android.app.action.DEVICE_ADMIN_ENABLED"<device-admin<device-admin<limit-password<watch-login /apk/res/android"<reset-password/><!--更改屏 -lock強制鎖屏<wipe-data刪除全部數(shù)據(jù)<expire-password/><!—使 <encrypted-storage/><!— 數(shù)據(jù)進行加密--<disable-camera使用相機失效publicpublicclassMyAdminReceiverextendsDeviceAdminReceiver}publicpublicstaticvoidactiveDevince(Contextcontext) Managermanager= ComponentNamecomponentName=newComponentName(context,if(!manager.isAdminActive(componentName))Intentintent=new Manager.EXTRA_DEVICE_ADMIN,componentName);context.startActivityForResult(intent,1);}}privateprivatebooleanisActive() Managermanager= ComponentNamename=newComponentName(this,return}<!--<!--請 狀態(tài)信息--<uses-permissionandroid:name="android.permission.READ_PHONE_STATE" <uses-permissionandroid:name="android.permission.READ_CONTACTS"<uses-permission PLETED" <uses-permissionandroid:name="android.permission.SEND_SMS"<!--接 的權(quán)限--<uses-permissionandroid:name="android.permission.RECEIVE_SMS"<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"功能四:歸屬地查詢與來電顯 APIDemo動畫效果,Database,號正則表達式,號歸屬查詢規(guī)則 號:共11位數(shù)字,第一個為:1,第二位為:3—8,前7位決定其歸屬匪警號碼:3模擬器:4:5位6,7,8,9publicstaticStringgetAddess(Stringnumber){Stringaddress=number;Databasedatabase= Database.openDatabase(path,null,publicstaticStringgetAddess(Stringnumber){Stringaddress=number;Databasedatabase= Database.openDatabase(path,null, 號1.共112第一個為3第二位為3--Stringreg=if(number.matches(reg)) Stringsql="selectlocationfromdata2whereid=(selectoutkeyfromdata1whereid=?)";Cursorcursor=newString[]{number.substring(0,if(cursor.moveToNext())number=}elseaddress="未知地 號}}elseswitch(number.length())case3://110,119,120address匪警號碼";case4://5554,5556address模擬器";case5://10086,10010address=" casecasecasecaseaddress本地號碼defaultif(number.startsWith("0")&&number.length()>9)Stringsql="selectlocationfromdata2wherearea=?";Cursorcursor=database.rawQuery(sql,newString[]{number.substring(1,if(cursor.moveToNext())Stringlocation=address=location.substring(0,location.length()-}cursor=database.rawQuery("selectlocationfromdata2whereareanewString[]{number.substring(1,if(cursor.moveToNext())Stringlocation=address=location.substring(0,location.length()-}}}}return}privatevoidsetStyle()privatevoidsetStyle()String[]items={"半透明", 橙","蘋果綠","孔雀藍","金屬灰new.setSingleChoiceItems(items,0,new{publicvoidonClick(DialogInterfacedialog,intwhich){.putInt(SpUtils.BG_COLOR_INDEX,}.setPositiveButton(android.R.string.ok,}publicpublicbooleanonTouch(Viewv,MotionEventevent)switch(event.getAction())caseMotionEvent.ACTION_DOWN:firstX=(int)event.getRawX();firstY=(int)event.getRawY();caseintmoveX=(int)intintmoveY=(int)event.getRawY();intdistanceX=moveX-firstX;intdistanceY=moveY-firstY;intnewLeft=iv_drag_location.getLeft()+intnewTop=iv_drag_location.getTop()+intnewRight=iv_drag_location.getRight()+intnewBottom=iv_drag_location.getBottom()+iv_drag_location.layout(newLeft,newTop,newRight,newBottom);firstX=moveX;firstY=caseintx=inty=SpUtils.getInstance(this).putInt(SpUtils.LOCATION_X,x);SpUtils.getInstance(this).putInt(SpUtils.LOCATION_Y,y);}return}windowManager=(WindowManager)getSystemService(Context.WINDOW_SERVICE);ephonyManager=( windowManager=(WindowManager)getSystemService(Context.WINDOW_SERVICE);ephonyManager=( Listenforchangestothedevicecall ephonyManager.listen(listener, private istenerlistener=new istener()publicvoidonCallStateChanged(intstate, ingNumber)switch(state) ephonyManager.CALL_STATE_IDLE://來電前或掛 ephonyManager.CALL_STATE_RINGING: ephonyManager.CALL_STATE_OFFHOOK:}}WindowManager.LayoutParamsWindowManager.LayoutParamsparamsnewWindowManager.LayoutParams();params.width=WindowManager.LayoutParams.WRAP_CONTENT;//寬度自適應(yīng)params.height=WindowManager.LayoutParams.WRAP_CONTENT;//高度自適應(yīng)params.format=PixelFormat.TRANSLUCENT;//設(shè)置成透明的params.typeWindowManager.LayoutParams.TYPE_PHONE使addressViewparams.flagsWindowManager.LayoutParamsFLAG_NOT_FOCUSABLE;//使addressViewintx=SpUtils.getInstance(this).getInt(SpUtils.LOCATION_X,-1);inty=SpUtils.getInstance(this).getInt(SpUtils.LOCATION_Y,-1);if(x!=-1){params.gravity=Gravity.LEFT|Gravity.TOP;params.x=x;params.y=}windowManager.addView(addressView,<!--window添加一個視圖(toast)publicpublicstaticbooleanisServiceRunning(Contextcontext,String{ActivityManageram=List<RunningServiceInfo>runningServices=am.getRunningServices(Integer.MAX_VALUEfor(RunningServiceInfoinfo:runningServices)StringserviceClassName=if(serviceClassName.equals(className))return}}returnreturn}功能五:1)管Context,AlertDialog<instrumentation<instrumentationandroid:name="android.test.InstrumentationTestRunner"android:targetPackage="com.atguigu.my_ms"/><uses-libraryandroid:name="android.test.runner"http://publicclassBlackNumberDaoTestextendspublicvoidInfo),Viewv, .add(1,1,1,.add(1,2,1,}publicboolean Itemitem) Info=(AdapterContext intposition switch(item.getItemId())casecase2:}return}2)來電關(guān)鍵技術(shù):Service,AIDL掛斷 添加AIDL privatevoidendCalltry//Classclazz=Class.forName("android.os.ServiceManager");Methodmethod=clazz.getMethod("getService",String.class);通過反射調(diào)用這個getService方法,然后拿到IBinder對象,然后就可以進行aidlIBinderiBinder=(IBinder)newObject[]{Context. EPHONY_SERVICE}); ephony=I }catch(Exceptione){}}privatevoiddeleteCallLog(finalStringnumber){finalUriuri=CallLog.Calls.CONTENT_URIprivatevoiddeleteCallLog(finalStringnumber){finalUriuri=CallLog.Calls.CONTENT_URI;getContentResolver().registerContentObserver(uri,newContentObserver(null){publicpublicvoidonChange(booleanselfChange){"number=?",newString[]{number});}}}<!-- 的權(quán)限:用于掛 <uses-permissionandroid:name="android.permission.CALL_PHONE"<!--讀寫:用在刪除--<uses-permissionandroid:name="android.permission.READ_CALL_LOG"<uses-permissionandroid:name="android.permission.WRITE_CALL_LOG"3)判斷騷 privateprivatevoidNotificationManagermanager=ingNumber)Intentintent=newIntent(this,NumberSecurityActivity.class); PendingIntentpi=PendingIntent.getActivity(this,0,intent,Notificationnotification=newmanager.notify(0,notification);} <uses-permissionandroid:name="android.permission.READ_CONTACTS"功能六:關(guān)鍵技術(shù) k,publicpublicMap<Boolean,List<AppInfo>>getAllAppInfos()throwsExceptionMap<Boolean,List<AppInfo>>map=newHashMap<Boolean,List<AppInfo>>();List<AppInfo>systemInfos=newArrayList<AppInfo>();map.put(truesystemInfoskeyList<AppInfo>customerInfos=newArrayList<AppInfo>();//只非系統(tǒng)的 應(yīng)map.put(false,PackageManagerpackageManager=context.getPackageManager();Intentintent=newIntent();List<ResolveInfo>resolveInfos=for(ResolveInfori:resolveInfos)StringpackageName=ri.activityInfo.packageName;Drawableicon=ri.loadIcon(packageManager);StringappName=booleanisSystemApp=isSystemApp(packageManager,packageName);AppInfoappInfo=newAppInfo(icon,appName,packageName,isSystemApp);if(appInfo.isSystemApp()){}else}}return}privatebooleanisSystemApp(PackageManagerpm,StringpackageName)throwsException{PackageInfopackageInfo=pm.getPackageInfo(packageName,0);return(packageInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)>}關(guān)鍵技術(shù) PopupWindow,/卸載/運行popupView=popupView=View.inflate(this,R.layout.popup_view,ll_app_uninstall=(LinearLayout)popupView.findViewById(R.id.ll_app_uninstall);ll_app_start=(LinearLayout)popupView.findViewById(R.id.ll_app_start);ll_app_share=(LinearLayout)popupView.findViewById(R.id.ll_app_share);popupWindow=newPopupWindow(popupView,240,view.getHeight());popupWindow.setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));popupWindow.showAsDropDown(view,50,0-view.getHeight());Animationanimation=newScaleAnimation(0f,1f,0f,1f);privateprivatevoidshareApp(StringappName)IntentintentnewIntent(Intent.ACTION_SEND); in");//純文本//intent.putExtra(Intent.EXTRA_SUBJECT,"應(yīng)用 intent.putExtra(Intent.EXTRA_TEXT," 一個不錯的應(yīng)用:"+appName);//內(nèi)容}privatevoidprivatevoidstartApp(StringpackageName)PackageManagerpackageManager=Intentintent=if(intent==null){Utils.showToast(this此應(yīng)用無法啟動");}else}}privateprivatevoiduninStallApp(AppInfoappInfo)if(appInfo.isSystemApp())Toast.makeText(this系統(tǒng)應(yīng)用不能卸載elseif(getPackageName().equals(appInfo.getPackageNameToast.makeText(this,"當(dāng)前應(yīng)用不能卸載!",0).show();}}elseIntentintent=newIntent(Intent.ACTION_DELETE);intent.setData(Uri.parse("package:"+appInfo.getPackageName()));}}receiverreceiver=newIntentFilterfilter=newIntentFilter(Intent.ACTION_PACKAGE_REMOVED); this.registerReceiver(receiver,filter);privateclassUninstallReceiverextendsBroadcastReceiver{publicvoidonReceive(Contextcontext,Intentintent)StringdataString= if(dataString!=null)AppInfoappInfo=newappInfo.packageName=dataString.substring(dataString.indexOf(":")+1);}}}功能七:程序鎖(難應(yīng)用的列表顯示,加鎖與 Database,ListView,BaseAdapter,TranslateAnimationService,ActivityManagerpublicvoidpublicvoidonItemClick(AdapterView<?>parent,Viewview,intposition,longid)//添加動畫效果,動畫結(jié)束后,就把鎖 改TranslateAnimationanimation=newTranslateAnimation(Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0f,Animation.RELATIVE_TO_SELF,0f);AppInfoappInfo=appInfoList.get(position);ViewHolderviewHolder=(ViewHolder)view.getTag();AppInfoappInfo=appInfoList.get(position);ViewHolderviewHolder=(ViewHolder)view.getTag();booleanlock=(Boolean)viewHolder.lockIV.getTag();if(lock){Uriuri getContentResolver().delete(uri,null,newString[]{appInfo.getPackageName()});}elseContentValuesvalues=newContentValues();values.put("packagename",appInfo.getPackageName());Uriuri= getContentResolver().insert(uri,values);}}:流程分析ContentProvider,ContentResolver,ContentObsver,Service,AppLockMonitorService-----啟動線程(一直運行獲取啟動的應(yīng)用信如果是,啟動界**privatevoidstartMonitor()newThread(newRunnable(){publicvoidrun()while(flag)1得到當(dāng)前最近啟動的應(yīng)用StringpackageName=Log.Log.e("TAG","startpn="+try2//判斷是否在臨時不鎖定的列表中,如果是不用顯 界如果在啟動一個鎖屏界面if(!tempUnlockNames.contains(packageName)appLockNames.contains(packageName))}}catch(InterruptedExceptione){}}}}privateStringgetTopPackageName()return}privatevoidstartLockScreenActivity(StringpackageName){Intentintent=newIntent(this,LockScreenActivity.class);intent.putExtra("packagename",packageName);}publicUripublicUriinsert(Uriuri,ContentValuesvalues)intmatch=if(match==1)StringpackageName=values.getAsString("packagename"); getContext().getContentResolver().notifyChange(URI,null);}elsethrownewRuntimeException("格式不正確}return}publicintdelete(Uriuri,Stringselection,String[]selectionArgs)intmatch=if(match==1){ getContext().getContentResolver().notifyChange(URI,null);}elsethrownewRuntimeException("格式不正確}return}UriuriUriurigetContentResolver().delete(uri,null,newString[]{appInfo.getPackageName()ContentValuesvalues=newContentValues();values.put("packagename",appInfo.getPackageName());Uriuri= getContentResolver().insert(uri,Uriuri=getContentResolver().registerContentObserver(uri,true,protectedContentObserverobserver=newContentObserver(newHandler())publicvoidonChange(booleanselfChange){appLockNames=appLockDao.getAll();Log.e("TAG","ContentObserveronChange()..");} Intentservice=newIntent(thisIntentservice=newIntent(this,service.putExtra("packageName",packageName);startService(service);功能八:關(guān)鍵技術(shù):PackageManager,ActivityManager,Asyn k,ListView,BaseAdapter,List<ProcessInfo>publicpublicstaticvoidgetAllProcessInfos(ContextList<ProcessInfo>systemProcessInfos,List<ProcessInfo>userProcessInfos)ActivityManageram=(ActivityManager)List<RunningAppProcessInfo>processInfos=am.getRunningAppProcesses();PackageManagerpm=context.getPackageManager();for(RunningAppProcessInfoprocessInfo:processInfos){ProcessInfoinfo=newProcessInfo();StringpackageName=processIcessName;應(yīng)用占用的內(nèi)存bit/byteMemoryInfomemoryInfoam.getProcessMemoryInfo(newint[]{processInfo.pid})[0];longmemInfoSize=memoryInfo.getTotalPrivateDirty()*1024;tryDrawableicon=pm.getPackageInfo(packageName,0).applicationInfo.loadIcon(pm);Stringname=pm.getPackageInfo(packageName,intflag=pm.getPackageInfo(packageName,if((flag&ApplicationInfo.FLAG_SYSTEM0)else}catch(NameNotFoundExceptione根據(jù)包名得到不到PackageInfo}if(info.isSystem()){}else}}}publicstaticpublicstaticlonggetAvailMem(Contextcontext)ActivityManageram=(ActivityManager)ActivityManager.MemoryInfooutInfo=newActivityManager.MemoryInfo();return}publicpublicstaticlonggetTotalMem(Contextcontext)longtotalMem=intsysVersionVERSION.SDK_INT下面的方式只能在JELLY_BEAN(16)if(sysVersion>=Build.VERSION_CODES.JELLY_BEAN){ActivityManageram=(ActivityManager)contextActivityManager.MemoryInfomemoryInfo=newActivityManager.MemoryInfo();totalMem=}elsetry{//在版本小于16時, Filefile=newFile("/proc/meminfo");FileInputStreamfis=newFileInputStream(file);BufferedReaderreader=newBufferedReader(newStringresult=reader.readLine();//MemTotal:510484kBresult=result.substring(result.indexOf(":")+1,result.indexOf("k")).trim();//totalMem=Integer.parseInt(result)*}catch(Exceptione){}}return}//返回格式化后的大小//返回格式化后的大小1.5GB12MB,16.66KB,StringFormatter.formatFileSize(context,<!--殺死進程--關(guān)鍵技術(shù)AppWidgetProvider,<appwidget-providerRemoteView,Service,PendingIntent,HandlerpublicclassProcessWidgetextendspublicclassProcessWidgetextendsAppWidgetProviderprivateIntentintent;publicvoidonEnabled(Contextcontext){//長按產(chǎn)生一個widgetintentnewIntent(context,UpdateWidgetService.class);}publicvoidonDeleted(Contextcontext,intappWidgetIds)移除桌面的if(intent!=null){intent=null;}}}<receiverandroid:name=".receiver.ProcessWidget"<receiverandroid:name=".receiver.ProcessWidget"<actionandroid:name="android.appwidget.action.APPWIDGET_UPDATE"android:resource="@xml/process_widget"/>publicvoidonCreate()publicvoidonCreate()manager= 視圖對remoteViews=newRemoteViews(getPackageName(),Intentintent=newIntent(this,UpdatewidgetService.class);intent.putExtra("clear",true);PendingIntentpendingIntent=PendingIntent.getService(this,0,intent,componentName=newComponentName(this,//發(fā)送延遲消息使用widget能每隔2handler.sendEmptyMessageDelayed(1,}privatevoidupdateWidget()processCountprocessCountMSUtils.getProcessCount(thisremoteViews.setTextViewText(R.id.tv_widget_process_count進程數(shù)為+availMemMSUtils.getAvailMem(thisremoteViews.setTextViewText(R.id.tv_widget_process_memory可用內(nèi)存為+Formatter.formatFileSize(this,availMem));manager.updateAppWidget(componentName,remoteViews);}privateScreeenReceiverprivateScreeenReceiverprivatevoidregistScreenReceiver(){receiver=newScreeenReceiver();IntentFilterfilter=newIntentFilter();filter.addAction(Intent.ACTION_SCREEN_ON);//filter.addAction(Intent.ACTION_SCREEN_OFF//registerReceiver(receiver,filter}privateclassScreeenReceiverextendsBroadcastReceiver{publicvoidonReceive(Contextcontext,Intentintent){Stringaction=intent.getAction();if(Intent.ACTION_SCREEN_ON.equals(action)){Log.e("TAG","開 }elseLog.e("TAG","鎖 }}}privateprivatevoidcreateShortcut()booleanshortcut=.getBoolean(SpUtils.SHORT_CUT,if(!shortcut)Intentintent=BitmapFactory.decodeResource(getResources(),intent.putExtra(Intent.EXTRA_SHORTCUT_NAME 衛(wèi)士//點擊快捷鍵IntentcallIntent=newIntent("com.atguigu.my_ms.action.Main");intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,callIntent);,SpUtils.getInstance(this).put(SpUtils.SHORT_CUTtrue);}}<!--生成應(yīng)用快捷方式功能九:關(guān)鍵技術(shù) PackageManager,AIDL,反射調(diào)用@hide的方 List<ApplicationInfo> List<ApplicationInfo>applications=Methodmethod=String.class,IPackageStatsObserver.class);method.invoke(pm,packageName,newIPackageStatsObserver.Stub(){publicvoid pleted(PackageStatspStats,booleansucceeded){longcacheSize=pStats.cacheSize);}權(quán)限 通過反射+AIDL調(diào)用PackageManagerhideMethodmethod=PackageManager.classMethodmethod=PackageManager.class.getMethod("deleteApplicationCacheFiles",String.class,IPackageDataObserver.class);method.invoke(pm,info.packageName,newIPackageDataObserver.Stub(){public pleted(Stringbooleansucceeded)throwsRemoteException}Intentintent=newIntentintent=newIntent();intent.setData(Uri.parse("package:"+功能十:publicstaticList<TrafficInfo>getAllTrafficInfos(Contextcontext)List<TrafficInfo>list=newPackageManagerpm=List<ApplicationInfo>infos=for(ApplicationInfoinfo:infos)TrafficInfotrafficInfo=newStringappName=info.loadLabel(pm).toString();Drawableicon=info.loadIcon(pm);intuid= longinSize=TrafficS
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度建筑工地臨時用工人員工資支付與爭議調(diào)解協(xié)議3篇
- 應(yīng)急管理概論 教學(xué)大綱
- 企業(yè)流程管理培訓(xùn)
- 二零二五年度廣告銷售渠道拓展合同范本3篇
- ChatGPT助推學(xué)校教育數(shù)字化轉(zhuǎn)型-人工智能時代學(xué)什么與怎么教
- 航空母艦發(fā)展史
- 炒菜放料知識培訓(xùn)課件
- 山西省朔州市懷仁市2024-2025學(xué)年七年級上學(xué)期1月期末生物試題(無答案)
- Unit6 Shopping A let's spell (說課稿)-2023-2024學(xué)年人教PEP版英語四年級下冊
- 第16章 分式 評估測試卷(含答案)2024-2025學(xué)年數(shù)學(xué)華東師大版八年級下冊
- 2024年個人汽車抵押借款合同范本(四篇)
- 春聯(lián)課件教學(xué)課件
- 北師大版五年級上冊脫式計算400道及答案
- 安徽省蕪湖市2023-2024學(xué)年高一上學(xué)期期末考試 地理試題
- 8《美麗文字 民族瑰寶》教學(xué)設(shè)計2023-2024學(xué)年統(tǒng)編版道德與法治五年級上冊
- 2024年工業(yè)廢水處理工(初級)技能鑒定考試題庫(含答案)
- 2024新滬教版英語初一上單詞表(英譯漢)
- NB/T 11446-2023煤礦連采連充技術(shù)要求
- 人教版八年級上冊生物期末必刷15道識圖題
- SY-T 6966-2023 輸油氣管道工程安全儀表系統(tǒng)設(shè)計規(guī)范
- 學(xué)生公寓管理員培訓(xùn)
評論
0/150
提交評論