如果要在Android 4.0或最新版本(不在下面)中卸载应用程序,如何显示消息?

时间:2014-05-23 12:10:21

标签: android broadcastreceiver

我想在Android 4.0中卸载应用程序时收到消息或警告,我收到的警告信息低于4.0但不是最新的。

这在SDK 10中正常运行,但在SDK 16或更高版本中无效。

这是我的BroadcastReceiver类

public class UninstallReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // fetching package names from extras
        String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES"); 

        if(packageNames!=null){
            for(String packageName: packageNames){
                if(packageName!=null && packageName.equals("com.example.sos")){
                   // start your activity here and ask the user for the password 

                    Intent intt = new Intent(context,EmailActivity.class);
                    intt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                     context.startActivity(intt);

                }
            }
        }
    }

    }

在Android manifest.xml中

<receiver android:name="com.example.pw.receiver.UninstallReceiver">
          <intent-filter android:priority="0">
                <action android:name="android.intent.action.QUERY_PACKAGE_RESTART" />
                <data android:scheme="package" />
          </intent-filter>
     </receiver>

它在Android SDK 16或Android 4.0下正常运行,但在最新版本中无效。

请帮我解决SDK兼容性问题。

提前致谢

1 个答案:

答案 0 :(得分:2)

在Android的更高版本中无法做到这一点。它曾经是可能的。

  

这在SDK 10中正常运行,但在SDK 16或更高版本中无效。

这是正确的 - 错误/功能已得到修复。


更新:我看到@CommonsWare在他自己的评论中留下了相同的答案:

  

如果可以,它代表Android中的安全漏洞。应用   当它们存在时,它们不应该能够得到控制   卸载。