Android的Browser.BOOKMARKS_URI不能在所有设备上工作。如何找出一个给定的设备的正确URI? [英] Android Browser.BOOKMARKS_URI does not work on all devices. How to find out the correct uri for a given device?
问题描述
我想使用Android Browser.BOOKMARKS_URI到CRUD设备的书签从我的应用程序中(的 https://play.google.com/store/apps/details?id=com.elementique.web )
它的工作罚款大部分设备,但在一些不工作: - (
在这些设备,试图使用书签导致
java.lang.IllegalArgumentException异常:未知的URL内容://浏览器/书签
我现在明白Boookmark乌里可以比AOSP默认值不同(即,内容://浏览器/书签)。
问:
我怎样才能在正确的书签乌里给定设备?
我已经'收集'以下URI
私有静态最终乌里BOKKMARKS_DEFAULT = Browser.BOOKMARKS_URI; // = Uri.parse(内容://浏览器/书签)
私有静态最终乌里BOKKMARKS_URI_CHROME = Uri.parse(内容://com.android.chrome.browser/bookmarks);
私有静态最终乌里BOKKMARKS_URI_SAMSUNG_S_ = Uri.parse(内容://com.sec.android.app.sbrowser.browser/bookmarks);
这是个办法名单所有可用的内容URI:在设备(内容// ...)?
如果是的话,我可以列出他们并搜索/书签串的发生,给这个URI一试。
的注意的:
我目前在如果应用程序是不是能够得到一个工作书签URI(即我自己的收藏DB,因为我需要在我的应用程序书签功能)创建回退机制的过程
有没有办法为列表所有可用的内容URI(内容:// ...)?在设备
块引用>有在的 Play商店可以列出所有可用的
内容://
URI在设备上。它采用PackageManager.GET_PROVIDER
下面是搜索所有可用的内容提供商各自的类:
SearchProviderTask.java
包com.jensdriller.contentproviderhelper.task;进口的java.util.ArrayList;
进口java.util.Collections中;
进口了java.util.Comparator;
进口的java.util.List;
进口java.util.Locale中;
进口android.content.Context;
进口android.content.pm.PackageInfo;
进口android.content.pm.PackageManager;
进口android.content.pm.ProviderInfo;
进口android.net.Uri;公共类SearchProvidersTask扩展DialogAsyncTask<开放的,无效的,列表与LT;弦乐>> {
公共SearchProvidersTask(上下文的背景下){
超级(上下文);
} @覆盖
保护列表与LT;弦乐> doInBackground(URI ... PARAMS){
清单<串GT; contentProviders =新的ArrayList<串GT;(); 尝试{
软件包管理系统下午= mContext.getPackageManager();
对于(PackageInfo包:pm.getInstalledPackages(PackageManager.GET_PROVIDERS)){
ProviderInfo [] =供应商pack.providers;
如果(供应商!= NULL){
对于(ProviderInfo提供商:提供商){
contentProviders.add(内容://+ provider.authority);
}
}
}
}赶上(例外五){
//软件包管理系统已经死亡?
mException = E;
} //按字母顺序排序,并忽略大小写
Collections.sort(contentProviders,新的比较<串GT;(){
@覆盖
公众诠释比较(LHS字符串,字符串RHS){
返回小写(左).compareTo(小写(右));
} 私人字符串小写(String s)将{
返回s.toLowerCase(Locale.getDefault());
}
});
返回contentProviders;
}
}Github上: https://github.com/jenzz/ContentProviderHelper
I am trying to use Android Browser.BOOKMARKS_URI to CRUD device bookmarks from within my app ( https://play.google.com/store/apps/details?id=com.elementique.web )
It's working fine on most of the devices, but does not work on some :-(
On those devices, trying to use bookmarks leads to
java.lang.IllegalArgumentException: Unknown URL content://browser/bookmarks
I now understand that Boookmark Uri can be different than the AOSP default value (i.e. "content://browser/bookmarks").
Question:
How can I get the correct Bookmark Uri for a given device?
I already 'collected' the following URI
private static final Uri BOKKMARKS_DEFAULT = Browser.BOOKMARKS_URI; // = Uri.parse("content://browser/bookmarks") private static final Uri BOKKMARKS_URI_CHROME = Uri.parse("content://com.android.chrome.browser/bookmarks"); private static final Uri BOKKMARKS_URI_SAMSUNG_S_ = Uri.parse("content://com.sec.android.app.sbrowser.browser/bookmarks");
Is it a way to 'list' all available content URI (content://...) on a devices? If yes, I could list them and search for occurrence of "/bookmarks" string and give a try with this URI.
Note:
I am currently in the process of creating a fallback mechanism if the app is not able to get a 'working' bookmark URI (i.e. my own Bookmark DB since I do need a bookmark feature in my app)
解决方案Is there a way to 'list' all available content URI (content://...) on a devices?
There's an opensource APP called "Content Provider Helper" in Play Store that can list all available
content://
URI on the device. It usesPackageManager.GET_PROVIDER
Here's the respective class that searches all available content provider:
SearchProviderTask.java
package com.jensdriller.contentproviderhelper.task; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Locale; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.net.Uri; public class SearchProvidersTask extends DialogAsyncTask<Uri, Void, List<String>> { public SearchProvidersTask(Context context) { super(context); } @Override protected List<String> doInBackground(Uri... params) { List<String> contentProviders = new ArrayList<String>(); try { PackageManager pm = mContext.getPackageManager(); for (PackageInfo pack : pm.getInstalledPackages(PackageManager.GET_PROVIDERS)) { ProviderInfo[] providers = pack.providers; if (providers != null) { for (ProviderInfo provider : providers) { contentProviders.add("content://" + provider.authority); } } } } catch (Exception e) { // PackageManager has died? mException = e; } // Sort alphabetically and ignore case sensitivity Collections.sort(contentProviders, new Comparator<String>() { @Override public int compare(String lhs, String rhs) { return lowerCase(lhs).compareTo(lowerCase(rhs)); } private String lowerCase(String s) { return s.toLowerCase(Locale.getDefault()); } }); return contentProviders; } }
Github: https://github.com/jenzz/ContentProviderHelper
这篇关于Android的Browser.BOOKMARKS_URI不能在所有设备上工作。如何找出一个给定的设备的正确URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!