Delphi 10.2.2 Firemonkey Android问题:如何在Android应用程序的Android浏览器中打开URL?
我试图理解这里的概念:How can I open a URL in Android's web browser from my application?但信息并没有帮助我。与我目前的代码相比,我无法将自己的大脑包围起来,让它们如何运作。
我也在这里看过:http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/FMX.Android_Intents_Sample
我也看过这里:https://developer.android.com/guide/components/intents-common.html?hl=en
我已尝试过此代码:
let list1 = [{Client_Issue_Reference__c:null,
End__c:"2018-03-06T23:00:00.000Z",
Id:"a0Q2F000000oRyBUAU",
Resource_Full_Name__c:"test user",
Start__c:"2018-03-06T15:00:00.000Z"}]
let list2 = [{Id:"0050W000006r0xnQAA",
IsActive:true,
Name:"test user"}]
list1.map(obj => {
let checker = list2.find(obj2 => obj2.Name === obj.Resource_Full_Name__c)
if (!checker) {
let buildingObjectAllUser = {}
sobjectType: "testObject"
buildingObjectAllUser.Id = listOne[i].Id
buildingObjectAllUser.Start__c = "2018-03-06T23:00:00.000Z"
buildingObjectAllUser.End__c = "2018-03-06T23:00:00.000Z"
buildingObjectAllUser.Name = "No Hours"
buildingObjectAllUser.Resource_Full_Name__c = listOne[i].Name
listThree.push(buildingObjectAllUser)
return buildingObjectAllUser
}
})
这是我使用该功能的方式:
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;
它一直给我一个错误:
错误:android.content.ActivityNotFoundException:找不到处理Intent的活动{act = android.intent.action.VIEW dat = https://www.patreon.com/phonelosers/overview/}
我也试过这段代码:
OpenURL('https://www.patreon.com/phonelosers/overview/', true)
给了我" Intent.resolveActivity< = 0"
使用哪款Android手机并不重要。我有一个Moto G Play,三星S8 +和一个运行Android版本6.0.1,7.0,8.0的Moto Z2 Force。所有手机都安装了Chrome网络浏览器,我可以使用它。
我浏览网页,下面的代码是每个人都在使用我应该做的事情。我查看了Delphi和Android编程信息。
请帮助解决这个Delphi 10.2.2 Firemonkey Android问题!
答案 0 :(得分:1)
使用不同的编码方法后:
procedure OpenURL(const URL: string);
var
LIntent: JIntent;
Data: Jnet_Uri;
begin
LIntent := TJIntent.Create;
Data := TJnet_Uri.JavaClass.parse(StringToJString(URL));
LIntent.setData(Data);
LIntent.setAction(StringToJString('android.intent.action.VIEW'));
TAndroidHelper.Activity.startActivity(LIntent);
end;
我发现我忘了" System.NetEncoding.TNetEncoding.URL.Encode"只是从源中删除该代码修复了该问题,以便此代码:
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(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;
现在有效!
由于 System.NetEncoding.TNetEncoding.URL.Encode 导致了这个问题,我想知道我是否需要对我的网址进行特殊编码,我应该使用什么?
答案 1 :(得分:0)
使用此代码:
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div style="border: 2px solid black;">
<c:import var="testHtml" url="/pay_new.html" />
<c:out value="${testHtml}" escapeXml="false" />
</div>