码迷,mamicode.com
首页 > 移动开发 > 详细

Android apk 监听

时间:2015-05-19 19:14:20      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:android   apk   广播   安装   卸载   

Android apk 安装、清理数据、强行停止、卸载监听


不废话,上代码


<receiver android:name="com.test.Receiver" android:enabled="true">
            <intent-filter >
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                <action android:name="android.intent.action.PACKAGE_CHANGED"/>
                <action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
                <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH"/>
                <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
                <action android:name="android.intent.action.PACKAGE_REPLACED"/>
                <action android:name="android.intent.action.PACKAGE_RESTARTED"/>
                <data android:scheme="package"></data>
            </intent-filter>
        </receiver>


以下是各个情况下,发送的广播


1\安装

android.intent.action.PACKAGE_ADDED


2覆盖安装
android.intent.action.PACKAGE_REMOVED
 android.intent.action.PACKAGE_ADDED
android.intent.action.PACKAGE_REPLACED


3\清理数据
 android.intent.action.PACKAGE_RESTARTED
android.intent.action.PACKAGE_DATA_CLEARED


4\强行停止
Action: android.intent.action.PACKAGE_RESTARTED


5\卸载
android.intent.action.PACKAGE_REMOVED
 android.intent.action.PACKAGE_FULLY_REMOVED


在广播中得到包名的方法 

ComponentName cn = intent.getComponent() ;
Uri uu= intent.getData() ;
String name = uu.getSchemeSpecificPart();

得到apk(未安装)相关信息:


public static void getAPKPackageInfo(Context context,String apkPath){
        PackageManager packageManager = context.getPackageManager();
        PackageInfo info = packageManager.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
        if(info != null){
            ApplicationInfo appInfo = info.applicationInfo;
            String appName = packageManager.getApplicationLabel(appInfo).toString();
            String packageName = appInfo.packageName;  //得到安装包名称
            String version=info.versionName;       //得到版本信息
            Drawable icon = packageManager.getApplicationIcon(appInfo);//得到图标信息
        }
    }



Android apk 监听

标签:android   apk   广播   安装   卸载   

原文地址:http://blog.csdn.net/u012664191/article/details/45846165

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!