手機安全衛士——病毒查殺

来源:http://www.cnblogs.com/mengxiao/archive/2017/02/10/6385278.html
-Advertisement-
Play Games

public class AntivirusActivity extends Activity { TextView tv_init_virus; ProgressBar pb; Message msg; ImageView iv_scanning; LinearLayout ll_content;... ...


public class AntivirusActivity extends Activity {    
    TextView tv_init_virus;
    ProgressBar pb;
    Message msg;
    ImageView iv_scanning;
    LinearLayout ll_content;
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        initUI();
        initData();
        
    }
    
    static class ScanInfo{
        boolean desc;
        String appname;
        String packagename;
    }
    
    
     Handler  handler = new Handler(){
         public void handleMessage(android.os.Message msg) {
             switch(msg.what){
             case 1:
                 tv_init_virus.setText("初始化八核殺毒引擎");
                 break;
             case 2:
                 //病毒掃描中
                 TextView child = new TextView(AntivirusActivity.this);
                 ScanInfo scaninfo = (ScanInfo) msg.obj;
                 if(scaninfo.desc){//true表示有病毒
                     child.setTextColor(Color.RED);
                     child.setText(scaninfo.appname+"有病毒");
                     
                 }else{
                     child.setTextColor(Color.BLACK);
                     child.setText(scaninfo.appname+"掃描安全");
                     
                 }               
                 ll_content.addView(child);
                 break;
             case 3:
                 //當掃描結束的時候,停止動畫。
                 iv_scanning.clearAnimation();               
                 break;          
             }
             
             
         };
    };
    
    public void initData(){
        
        
        new Thread(){
            
            public void run(){
//                //獲取手機裡面所有的應用程式
//                List<AppInfo> appinfos = AppInfos.getAppInfos(AntivirusActivity.this);
//                //迭代手機上邊所有的軟體
//                for(AppInfo appinfo:appinfos){
//                    String name = appinfo.getApkname();
//                }
                
                msg = Message.obtain();
                msg.what = 1;//初始化病毒                                              
                PackageManager packageManager = getPackageManager();
                List<PackageInfo> installPackages = packageManager.getInstalledPackages(0);
                
                int size = installPackages.size();
                pb.setMax(size);
                int progress = 0 ;
                
                for(PackageInfo packageinfo:installPackages){
                    //獲取當前手機上app的名字
                    String appname = packageinfo.applicationInfo.loadLabel(packageManager).toString();
                    //首先需要獲取到每個應用程式的位置
                    String sourceDir = packageinfo.applicationInfo.sourceDir;
                    ScanInfo scaninfo = new ScanInfo();
                    
                    scaninfo.appname = appname;
                    scaninfo.packagename = packageinfo.applicationInfo.packageName;
                    
                    //MD5是病毒特征碼,得到應用程式的MD5值
                    
                        String md5 = null;
                        try {
                            md5 = MD5Utils.getFileMd5(sourceDir);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        String desc = AntivirusDao.checkFileVirus(md5);
                        if(desc == null){
                            scaninfo.desc = false;
                            
                        }else{
                            //這裡有病毒
                            scaninfo.desc = true;
                        }
                        progress++;
                        pb.setProgress(progress);
                        msg = Message.obtain();
                        msg.what = 2;//正在瀏覽
                        msg.obj = scaninfo;
                        handler.sendMessage(msg);                                       
                    //判斷當前的文件是否在病毒資料庫中?                                
                }
                msg = Message.obtain();
                msg.what = 3;//結束                
                handler.sendMessage(msg);
                
            }
        }.start();
        
        
        
        
    }

    
    public void initUI(){
        setContentView(R.layout.activity_antivirus);
        iv_scanning = (ImageView) findViewById(R.id.iv_scanning);
        ll_content = (LinearLayout) findViewById(R.id.ll_content);
        tv_init_virus = (TextView) findViewById(R.id.tv_init_virus);
        pb =  (ProgressBar) findViewById(R.id.progressBar1);
        /**
         * fromDegrees 開始的角度
         * toDegrees 結束的角度
         * pivotXType 參照自己
         * pivotXValue 
         * pivotYType 
         * pivotYValue 
         * 初始化旋轉動畫
         */
        
        RotateAnimation rotationmation = new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);
        rotationmation.setDuration(5000);
        //rotationmation.setRepeatMode(-1);
        rotationmation.setRepeatCount(-1);
        iv_scanning.startAnimation(rotationmation);
    }
}
AntivirusDao.java
public class AntivirusDao {
    //檢查當前MD5是否在資料庫中
    public static String checkFileVirus(String md5){
        String desc = null;
        SQLiteDatabase db = SQLiteDatabase.openDatabase("data/data/com.mxn.mobilesafe/files/antivirus.db", null, 
SQLiteDatabase.OPEN_READONLY);
//查詢 Cursor cursor = db.rawQuery("select desc from datable where md5 = ?", new String[]{md5}); if(cursor.moveToNext()){ cursor.getString(0); } return desc; } //添加病毒資料庫 public static void adddVirus(String md5,String desc){ SQLiteDatabase db = SQLiteDatabase.openDatabase("data/data/com.mxn.mobilesafe/files/antivirus.db", null, SQLiteDatabase.OPEN_READONLY); ContentValues values = new ContentValues(); values.put("md5", md5); values.put("desc", desc); values.put("type", 6); values.put("name", "Android.Adware.AirAD.a"); db.insert("datable", null, values); db.close(); } }
activity_antivirus.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    
    xmlns:android="http://schemas.android.com/apk/res/android">
    
     <TextView 
        style="@style/TitleStyle"
        android:text="病毒查殺"
        />
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:orientation="horizontal" >
    
   
    <FrameLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        
        >
       
       <ImageView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_scanner_malware"
    />
         <ImageView 
             android:id="@+id/iv_scanning"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/act_scanning_03"
    />                     
    </FrameLayout>

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_margin="5dp"
    >        
    <TextView 
    android:id="@+id/tv_init_virus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="初始化8核殺毒引擎"    
    />
    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar1"       
        ></ProgressBar>
</LinearLayout>
</LinearLayout>    
   <LinearLayout
        android:orientation="vertical"
        android:id="@+id/ll_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ></LinearLayout>     
</LinearLayout>

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 我們來講一下組合模式: 怎麼是組合模式呢?組合模式,將對象組合成樹形結構以表示‘部分-整體’的層次結構,組合模式是的用戶對單個對象和組合對象的用用具有一致性。 與一個很簡單的例子,公司的組織架構,大都是樹枝結構的。下麵,我們來看一下如何用組合模式寫樹枝結構。 客戶端 結果: 好,是不是很簡單啊…… ...
  • 外觀模式 目的:的意圖是為子系統提供一個介面,方便其使用。 外觀模式常用於一些常規的應用程式的開發,因為一般都會對子系統的類進行重構,所以外觀類主要的職責就是為了給子系統提供簡單的訪問方式, 使其有一個明確的目的,從而完成對系統的重構。外觀類介於工具類和應用程式之間。 要註意實例與外觀的區別: 1、 ...
  • 官網:http://www.haproxy.org/ 個人感覺haproxy學習的重點在於配置上,把配置文檔搞懂了就明白大部分套路了。不過本篇內容屬於入門學習:1.使用haproxy簡單的實現負載均衡的效果。2.使用自帶監控查看效果。後續待學習的方向是訪問日誌配置、優化等~ 簡介: 我在虛擬機上裝的 ...
  • 一,基本思路:利用C#的標簽和反射功能實現自定義輕量級ORM 標簽Attribute附著在實體屬性或實體類名上,這樣可以取到實體對應的表名,屬性對應的表欄位名,數據類型,是否主鍵,欄位註釋等基本信息 反射實現對實體動態賦值取值。 二,比較重要的類 1、ISqlHelper:介面,定義數據操作的基本方 ...
  • Swagger Web API 文檔 Web API 線上文檔 Web API 手冊 Web API 線上手冊 ...
  • 前言 本文是對《大型網站架構設計》(李智慧 著)一書的梳理,類似文字版的“思維導圖” 全文主要圍繞“性能,可用性,伸縮性,擴展性,安全”這五個要素 性能,可用性,伸縮性這幾個要素基本都涉及到應用伺服器,緩存伺服器,存儲伺服器這幾個方面 本文是對《大型網站架構設計》(李智慧 著)一書的梳理,類似文字版 ...
  • 作者:ASO100鏈接:https://zhuanlan.zhihu.com/p/23041522來源:知乎著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。 自從 8 月中旬蘋果向開發者發佈了一封關於“上傳至 App Store 的 App 可設置一套尺寸相同的截圖“的郵件以來, ...
  • CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath]; CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableVie ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...