Get intent of uninstall app in android

北战南征 提交于 2019-12-09 13:29:54

问题


I just want to know about intent of uninstall app because of

in my app when user opens the first screen then the device id will be saved in server side by using php.

When user uninstall this app then automatically the device will be deleted in server side.

For this i prepared code for php for delete device id. So when will i call this webservive.

I tried below code

public class MyReceiver extends BroadcastReceiver {

@Override
 public void onReceive(Context context, Intent intent) {
 String action = intent.getAction(); 
 if("android.intent.action.PACKAGE_REMOVED".equals(action)){
   // here i wrote the code of  delete device id in server side
}

But it is not working because the intent was not raised. So please tell me what intent will be raise when user uninstall the app or tell me any suggestions for solve my problem.

Thanks in advance.

Regards


回答1:


You cannot get the uninstall intent for your own app. See this thread for more - Get application uninstall event in android




回答2:


You can detect uninstall pop up of any app(including your own app) using Accessibility Service.

public class MyService extends AccessibilityService {

@Override
public void onCreate() {
    super.onCreate();
}

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {

        if(event.getText().equalsIgnoreCase("check for content in popup which is in screenshot"){

        /**Do your task*/
        }
    }
}

@Override
public void onInterrupt() {
}

@Override
protected void onServiceConnected() {
    super.onServiceConnected();
    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.flags = AccessibilityServiceInfo.DEFAULT;
    info.packageNames = new String[]{"com.android.packageinstaller"};
    info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
    info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
    setServiceInfo(info);
}

here in onServiceConnected, [![com.android.packageinstaller][1]][1] represents the install/uninstall app package name(this is system app and it doesn't have any UI so it will not shown to users.).




回答3:


<receiver android:name=".MyReceiver">
<intent-filter android:priority="999"> 
    <action android:name="android.intent.action.PACKAGE_REMOVED"/>
    <data android:scheme="package"/> 
</intent-filter>
</receiver>

test in Android 4.0 and its works fine



来源:https://stackoverflow.com/questions/6775514/get-intent-of-uninstall-app-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!