gpt4 book ai didi

Kindle HD 上的 Android BrowserActivity

转载 作者:行者123 更新时间:2023-11-29 17:53:17 25 4
gpt4 key购买 nike

我有一个 Android 应用程序可以创建本地 HTML 文件,然后在浏览器中将其显示给用户。我遇到过 BrowserActivity 无法在不同设备上运行的问题,具体取决于安装的浏览器。我当前的代码执行以下操作 -

    public void displayStats()
{
String file = produceStats();
Uri uri = Uri.parse("file://" + file);

// chrome ??
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setDataAndType(uri, "multipart/related");

// default "Internet" browser
Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
intent2.setDataAndType(uri, "text/html");
intent2.setClassName("com.android.browser", "com.android.browser.BrowserActivity");

// any other browser (FireFox) ??
Intent intent3 = new Intent(Intent.ACTION_VIEW);
intent3.setDataAndType(uri, "text/html");
intent3.addCategory(Intent.CATEGORY_BROWSABLE);

PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities1 = packageManager.queryIntentActivities(intent1, 0);
List<ResolveInfo> activities2 = packageManager.queryIntentActivities(intent2, 0);
List<ResolveInfo> activities3 = packageManager.queryIntentActivities(intent3, 0);

boolean isIntentSafe1 = activities1.size() > 0;
boolean isIntentSafe2 = activities2.size() > 0;
boolean isIntentSafe3 = activities3.size() > 0;

List<Intent> targetedShareIntents = new ArrayList<Intent>();

if (isIntentSafe1)
{
unpackResolvedIntents(uri, "multipart/related", activities1, targetedShareIntents);
}
if (isIntentSafe2) {
unpackResolvedIntents(uri, "text/html", activities2, targetedShareIntents);
}
if (isIntentSafe3) {
unpackResolvedIntents(uri, "text/html", activities3, targetedShareIntents);
}

if (targetedShareIntents.isEmpty()) {
// go to market to install app ????
Toast.makeText(plink.this, "Please install BROWSER to complete (Chrome)", Toast.LENGTH_LONG).show();
Intent goToMarket = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("market://details?id=com.android.chrome"));
startActivity(goToMarket);
} else if (targetedShareIntents.size() == 1) {
startActivity(targetedShareIntents.remove(0));
} else {
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select viewer");
Intent[] extraIntents = new Intent[targetedShareIntents.size()];
for (int i = 0; i < targetedShareIntents.size(); i++) {extraIntents[i] = targetedShareIntents.get(i);}
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);

startActivity(chooserIntent);
}

}

produceStats() 调用返回文件路径,然后此函数的其余部分处理各种不同的浏览器,如果有多个可用浏览器,它会为用户提供一个选择器。

我的问题是,一位用户报告说,当他在装有 SILK 浏览器的 Kindle HD 设备上运行该应用程序时,应用程序崩溃了。因此,他的堆栈转储是 -

26 Jan 2014 16:26:09 GMT:Uncaught exception in java.lang.Thread:main(Unable to find explicit activity class {com.android.browser/com.android.browser.BrowserActivity}; have you declared this activity in your AndroidManifest.xml?)
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.browser/com.android.browser.BrowserActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1624)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1418)

我的问题是 - 如何在 Kindle 上启动以在 SILK 中显示文件?谢谢

最佳答案

基于对其 list 的检查,Kindle Fire HD 上的 Slik 似乎不支持 HTML 的 file:// 方案。它似乎只支持 http://https://inline://。我无法解释您遇到的具体崩溃,因为我没有看到 AOSP 浏览器应用程序的任何迹象,所以我不知道为什么 PackageManager 会以其他方式报告。

关于Kindle HD 上的 Android BrowserActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21414492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com