<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 93,  comments - 2,  trackbacks - 0
        在android系統中,安裝和卸載都會發送廣播,當應用安裝完成后系統會發android.intent.action.PACKAGE_ADDED廣播。可以通過intent.getDataString()獲得所安裝的包名。當卸載程序時系統發android.intent.action.PACKAGE_REMOVED廣播。同樣intent.getDataString()獲得所卸載的包名。
    第一、 新建監聽類:BootReceiver繼承BroadcastReceiver
        
    public class BootReceiver extends BroadcastReceiver {    
       
        @Override   
        
    public void onReceive(Context context, Intent intent) {    
            
    //接收廣播:系統啟動完成后運行程序    
            if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {    
                 Intent newIntent 
    = new Intent(context, WatchInstall.class);    
                 newIntent.setAction(
    "android.intent.action.MAIN");       
                 newIntent.addCategory(
    "android.intent.category.LAUNCHER");     
                 newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);       
                 context.startActivity(newIntent);    
            }
        
            
    //接收廣播:設備上新安裝了一個應用程序包后自動啟動新安裝應用程序。    
            if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {    
                String packageName 
    = intent.getDataString().substring(8);    
                System.out.println(
    "---------------" + packageName);    
                Intent newIntent 
    = new Intent();    
                newIntent.setClassName(packageName,packageName
    + .MainActivity");    
                newIntent.setAction("android.intent.action.MAIN");             
                newIntent.addCategory(
    "android.intent.category.LAUNCHER");             
                newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
                context.startActivity(newIntent);    
            }
        
            
    //接收廣播:設備上刪除了一個應用程序包。    
            if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {    
                System.out.println(
    "********************************");    
                DatabaseHelper dbhelper 
    = new DatabaseHelper();    
                dbhelper.executeSql(
    "delete from users");    
            }
        
        }
       

    第二、 修改AndroidManifest.xml配置文件 
    <?xml version="1.0" encoding="UTF-8"?>  
    <manifest xmlns:android="     package="org.me.watchinstall">  
        <application>  
            <receiver android:name=".BootReceiver"  
                      android:label="@string/app_name">  
                <intent-filter>  
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>  
                    <category android:name="android.intent.category.LAUNCHER" />  
                </intent-filter>  
                <intent-filter>  
                 <action android:name="android.intent.action.PACKAGE_ADDED" />  
                 <action android:name="android.intent.action.PACKAGE_REMOVED" />  
                  <data android:scheme="package" />  
    <!--[color=red] 注意!! 這句必須要加,否則接收不到BroadCast  [/color] -->
                </intent-filter>  
            </receiver>  
            <activity android:name=".WatchInstall" android:label="WatchInstall">  
                <intent-filter>  
                    <action android:name="android.intent.action.MAIN"/>  
                    <category android:name="android.intent.category.LAUNCHER"/>  
                </intent-filter>  
            </activity>  
        </application>  
        <uses-permission android:name="android.permission.INTERNET" />  
        <uses-permission android:name="android.permission.RESTART_PACKAGES"/>  
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>  
    </manifest>
    <2014年2月>
    2627282930311
    2345678
    9101112131415
    16171819202122
    2324252627281
    2345678

    常用鏈接

    留言簿(2)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    收藏夾

    Java

    搜索

    •  

    最新隨筆

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产一级一片免费播放i| 成年女人看片免费视频播放器| 亚洲av无码成人精品区| 精品国产亚洲一区二区三区在线观看| 91麻豆最新在线人成免费观看| 亚洲精品在线播放视频| 国产免费AV片无码永久免费| 亚洲制服丝袜中文字幕| 成年女人毛片免费观看97| 亚洲精品无码一区二区| 免费看AV毛片一区二区三区| 精品久久久久久亚洲中文字幕 | 搜日本一区二区三区免费高清视频 | 亚洲国产日韩在线成人蜜芽| 久草视频在线免费| 国产成人精品日本亚洲18图| 免费高清在线影片一区| 黄页网站在线观看免费| 五月亭亭免费高清在线| 亚洲mv国产精品mv日本mv| 最新猫咪www免费人成| 亚洲精品av无码喷奶水糖心| 亚洲国产精品丝袜在线观看| 拍拍拍无挡免费视频网站| 精品无码一区二区三区亚洲桃色 | 国产成人精品免费视频动漫 | 亚洲人和日本人jizz| 午夜免费不卡毛片完整版| 特a级免费高清黄色片| 亚洲国语精品自产拍在线观看| 91免费播放人人爽人人快乐| 菠萝菠萝蜜在线免费视频| 亚洲AV无码久久精品狠狠爱浪潮| 91短视频免费在线观看| 麻豆69堂免费视频| 亚洲黄色三级网站| 国产18禁黄网站免费观看| 久久午夜无码免费| 亚洲国产精品久久久久秋霞小 | 亚洲国产成人久久77| 亚洲av无码国产精品色在线看不卡|