Delphi 10.2.2 Firemonkey Android 问题:如何从我的应用程序中打开 Android 网络浏览器中的 URL?
我试图理解这里的概念:如何从我的应用程序在 Android 的网络浏览器中打开 URL? https://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application但这些信息对我没有任何帮助。与我目前拥有的代码相比,我无法理解他们如何让它工作。
我也看过这里:http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/FMX.Android_Intents_Sample http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/FMX.Android_Intents_Sample
我也看过这里:https://developer.android.com/guide/components/intents-common.html?hl=en https://developer.android.com/guide/components/intents-common.html?hl=en
我试过这段代码:
function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
var
Intent: JIntent;
begin
// There may be an issue with the geo: prefix and URLEncode.
// will need to research
Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
TJnet_Uri.JavaClass.parse(StringToJString(System.NetEncoding.TNetEncoding.URL.Encode(URL))));
try
TAndroidHelper.Activity.startActivity(Intent);
exit(true);
except
on e: Exception do
begin
if DisplayError then ShowMessage('Error: ' + e.Message);
exit(false);
end;
end;
end;
这就是我使用该功能的方式:
OpenURL('https://www.patreon.com/phonelosers/overview/', true)
它一直给我一个错误:
错误:android.content.ActivityNotFoundException:找不到处理 Intent { act=android.intent.action.VIEW dat= 的活动https://www.patreon.com/phonelosers/overview/ https://www.patreon.com/phonelosers/overview/ }
我也尝试过这段代码:
function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
var
Intent: JIntent;
begin
// There may be an issue with the geo: prefix and URLEncode.
// will need to research
Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
TJnet_Uri.JavaClass.parse(StringToJString(System.NetEncoding.TNetEncoding.URL.Encode(URL))));
if TAndroidHelper.Activity.getPackageManager.queryIntentActivities(Intent, TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size > 0 then
begin
try
TAndroidHelper.Activity.startActivity(Intent);
exit(true);
except
on e: Exception do
begin
if DisplayError then ShowMessage('Error: ' + e.Message);
exit(false);
end;
end;
end
else
begin
ShowMessage('Intent.resolveActivity <= 0');
end;
end;
这给了我“Intent.resolveActivity
我使用哪款 Android 手机并不重要。我有一台 Moto G Play、三星 S8+ 和一台 Moto Z2 Force,它们运行 Android 版本 6.0.1、7.0、8.0。所有手机都安装了 Chrome 网络浏览器,我可以使用它。
我浏览了整个网络,下面的代码是每个人都用来做我需要它做的事情的。我查看了Delphi和Android编程资料。
请帮助解决这个 Delphi 10.2.2 Firemonkey Android 问题!