我有一个带有“http”意图过滤器的 Android 应用程序。安装后,当用户在浏览器中按下 URL 时,会出现“打开方式”对话框。我的问题是:如果用户错误地选择了“始终使用 x 打开”并且他想更改他的选择以使用另一个应用程序打开 url,他如何才能再次获得“选择应用程序”对话框?
问问题
239 次
1 回答
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;
}
}
在显示“打开方式”之前清除缓存。
于 2016-09-22T09:02:09.500 回答