在Android中再次显示“打开方式”对话框

时间:2016-09-22 08:27:40

标签: android intentfilter open-with

我有一个Android应用,其中包含针对“http”的意图过滤器。安装完成后,用户在浏览器中按下网址时会显示“打开方式”对话框。 我的问题是:如果用户选择错误地“用x打开总是”并且他想改变他的选择以用另一个应用程序打开网址,他怎么能再次获得“选择应用程序”对话框?

1 个答案:

答案 0 :(得分:0)

您必须清除应用程序的缓存。

要清除缓存,您已获得许可 -

<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>

致电deleteCahce()清除cahe

public static void deleteCache(Context context) {
    try {
        File dir = context.getCacheDir();
        deleteDir(dir);
    } catch (Exception e) {}
}

public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            boolean success = deleteDir(new File(dir, children[i]));
            if (!success) {
                return false;
            }
        }
        return dir.delete();
    } else if(dir!= null && dir.isFile()) {
        return dir.delete();
    } else {
        return false;
    }
}

在显示&#34;打开&#34;。

之前清除缓存