Sending a URL to Another App on Android and iOS with Delphi XE5
来源:互联网 发布:淘宝店铺怎么改折扣 编辑:程序博客网 时间:2024/06/08 02:16
Here is the source code for my Open and View URL library from my CodeRage 8 session “Beyond the App”. Here is a download of the example app. I’ll see about posting it to a SVN repository too so it can grow and evolve. Thanks to Al Mannarino for his code that started this!
Note the code is using TidURL.URLEncode on all URLs. I found it is only required on the maps for iOS (iOS doesn’t like spaces) but may be causing trouble with the geo:// on Android.
Some example protocols
- http, tel, sms, fb, mailto, twitter, geo, etc.
Example URLs
- – Common to both iOS & Android –
- http://www.embarcadero.com/
- tel://(415)834-3131
- sms://1234
- http://twitter.com/coderage (This opens with the Twitter client on Android)
- mailto://jim.mckeeth@embarcadero.com
- twitter://user?screen_name=coderage
- fb://profile/34960937498 (get the UID from http://graph.facebook.com/embarcaderotech or for whatever page you are looking for)
- – iOS Specific –
- http://maps.apple.com?q=5617 Scotts Valley Drive, Scotts Valley, CA 95066 (this needs the URL encode – Apple has some additional APIs that are recommended.)
- – Android Only –
- content://contacts/people/
- content://contacts/people/1
- geo://0,0?q=5617 Scotts Valley Drive, Scotts Valley, CA 95066
- geo://46.191200, -122.194400 (I think this one doesn’t like the URLEncode)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
unit
OpenViewUrl;
interface
// URLEncode is performed on the URL
// so you need to format it protocol://path
function
OpenURL(
const
URL:
string
;
const
DisplayError:
Boolean
=
False
):
Boolean
;
implementation
uses
IdURI, SysUtils, Classes, FMX
.
Dialogs,
{$IFDEF ANDROID}
Androidapi
.
Helpers,
FMX
.
Helpers
.
Android, Androidapi
.
JNI
.
GraphicsContentViewText,
Androidapi
.
JNI
.
Net, Androidapi
.
JNI
.
JavaTypes;
{
$ELSE
}
{$IFDEF IOS}
Macapi
.
Helpers, iOSapi
.
Foundation, FMX
.
Helpers
.
iOS;
{$ENDIF IOS}
{$ENDIF ANDROID}
function
OpenURL(
const
URL:
string
;
const
DisplayError:
Boolean
=
False
):
Boolean
;
{$IFDEF ANDROID}
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(TIdURI
.
URLEncode(URL))));
try
SharedActivity
.
startActivity(Intent);
exit(
true
);
except
on
e: Exception
do
begin
if
DisplayError
then
ShowMessage(
'Error: '
+ e
.
Message);
exit(
false
);
end
;
end
;
end
;
{
$ELSE
}
{$IFDEF IOS}
var
NSU: NSUrl;
begin
// iOS doesn't like spaces, so URL encode is important.
NSU := StrToNSUrl(TIdURI
.
URLEncode(URL));
if
SharedApplication
.
canOpenURL(NSU)
then
exit(SharedApplication
.
openUrl(NSU))
else
begin
if
DisplayError
then
ShowMessage(
'Error: Opening "'
+ URL +
'" not supported.'
);
exit(
false
);
end
;
end
;
{
$ELSE
}
begin
raise
Exception
.
Create(
'Not supported!'
);
end
;
{$ENDIF IOS}
{$ENDIF ANDROID}
end
.
阅读全文
0 0
- Sending a URL to Another App on Android and iOS with Delphi XE5
- Sending the User to Another App
- Sending the User to Another App
- Sending the User to Another App
- Sharing Files with NFC ->Sending Files to Another Device
- 16Sending the User to Another App(隐式Intent意图)
- Sharekit - sending a url link to facebook
- How To Setup a Rails 4 App With Apache and Passenger on CentOS 6
- [WP7] How to press the mouse on a control, and detect MouseLeftButtonUp on another
- Delphi XE5建立第一个Delphi Android app程序
- 【kafka】Exception thrown when sending a message with key='null' and payload='lizhenjuan;99' to topic
- Find closest point on a Linestring to another point
- Delphi XE5 Android Dialogs 对话框
- How to unshelve a shelveset into another branch with TFS
- java.lang.RuntimeException: Handler{405c1180} sending message to a Handler on a dead thread
- 使用AsyncTask引发RuntimeException:sending message to a Handler on a dead thread
- aMap.animateCamera不起作用,捕获异常Handler sending message to a Handler on a dead thread
- iOS - Choose a destination with a supported architecture in order to run on this device:
- itextPdf 中的一些细节问题
- ubuntu桌面上给文件夹创建快捷方式
- 瀑布流
- 《程序员的自我修养》第二章笔记
- php+html图片上传处理
- Sending a URL to Another App on Android and iOS with Delphi XE5
- React-Router去掉后便跟随的k参数
- java创建对象
- spark2.0访问ES5.1中的数据
- tomcat avicon.ico
- Manthan, Codefest 17-C-Helga Hufflepuff's Cup(树形DP)
- AJAX学习笔记(三)_XMLHttpRequest向服务器发送请求
- React 组件基本使用(三) ---父子组件之间的通信
- 【Web】Javascript多项式计算器