我正在尝试使用广播接收器检测应用程序卸载。
我管理我的应用程序,创建一个没有活动的接收器
应用程序卸载。当我第一次运行我并转到
时应用程序 - >管理应用程序 - >卸载它仅适用于一个
app,但在此之后没有收到任何回复
我的接收器向您显示
公共类AppReceiver扩展了BroadcastReceiver {
@Override
public void onReceive(Context ctx, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED))
{
Intent i=new Intent(ctx.getApplicationContext(),AppUninstall.class);
ctx.startService(i);
}
}
}
我已在接收器的清单文件中添加了此操作
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name="r.c.a.AppReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="r.c.a.AppUninstall" android:enabled="true"></service>
</application>
从接收器类开始服务
ublic class AppUninstall扩展了服务{
private final IBinder mBinder = new LocalBinder();
String pack;
NotificationManager nfm;
Notification nf;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return mBinder;
}
@Override
public void onCreate() {
}
@Override
public void onDestroy() {
}
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Launch a background thread to do processing.
super.onStartCommand(intent, flags, startId);
pack=intent.getPackage();
nfm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int NOTIFICATION_ID = 1;
Intent intent1 = new Intent();
PendingIntent pi = PendingIntent.getActivity(AppUninstall.this, 1, intent1, 0);
nf=new Notification(R.drawable.ic_launcher,"App Uninstalled",System.currentTimeMillis());
nf.setLatestEventInfo(getApplicationContext(), pack, null, pi);
startForeground( NOTIFICATION_ID,nf);
return Service.START_STICKY;
}
public class LocalBinder extends Binder {
AppUninstall getService() {
return AppUninstall.this;
}
}
}
请任何人提前帮助我