2011-11-22 122 views
1

我使用下面的代码来获取卸载程序包广播接收器,但我没有得到任何答复。任何人都可以说代码有什么问题。卸载应用程序接收器

AndroidManifest.xml 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="pack.test" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk android:minSdkVersion="8" /> 


    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:label="@string/app_name" 
      android:name=".TestprojectActivity" > 
      <intent-filter > 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <receiver android:name="UninstallApk"> 
      <intent-filter> 
       <action android:name="android.intent.action.PACKAGE_REMOVED"/> 
       <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/> 
      </intent-filter> 
     </receiver> 
    </application> 

</manifest> 


UninstallApk.java 

    import android.content.BroadcastReceiver; 
    import android.content.Context; 
    import android.content.Intent; 
    import android.util.Log; 
    import android.widget.Toast; 

    public class UninstallApk extends BroadcastReceiver { 

     @Override 
     public void onReceive(Context context, Intent intent) { 
      Log.i("DATA", "Apk uninstall"); 
      Toast.makeText(context,"APK uninstall",Toast.LENGTH_LONG).show(); 
     } 

    } 

当我插上充电器,它为我敬酒,但是当我卸载其他任何申请表格应用程序 - >管理应用程序它不显示任何回应。

谢谢。

+1

的可能重复[接收包的安装和卸载事件](http://stackoverflow.com/questions/7470314/receiving-package-install-and-uninstall-events) – Reno

回答

2

请首先搜索关于SO的问题,并且您可能会得到您想要的答案,因为有人提出了这个问题。

在你的情况下,你必须设置BroadcastReceiver的dataSchema。我已经回答了这样的问题(它也适用于PACKAGE_REMOVED行动)。看到这个链接here

-1

您需要添加android.permission.BROADCAST_PACKAGE_REMOVEDAndroidManifest.xml