最近我收到了来自 Dropbox
的消息:
您的Android应用当前正在Web视图中处理OAuth应用程序授权流程,而不是系统浏览器 .
所以我必须将 OAuth
app授权从 TWebBrowser
更改为 Intents
.
所以这是我的问题 . 如何从系统浏览器获取数据以及如何在授权完成后关闭浏览器?
我曾尝试使用下面的代码,但只有在关闭系统浏览器时才收到 “Cancelled”
消息 .
我的代码:
procedure TfrmmDropBoxIntent.Button1Click(Sender: TObject);
var
Intent: JIntent;
ResolveInfo: JResolveInfo;
begin
try
sURL :=
'https://www.dropbox.com/oauth2/authorize' +
'?response_type=token' +
'&client_id=' + cloudDropBoxID +
'&redirect_uri=http://localhost/';
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification, HandleActivityMessage);
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setData(StrToJURI(sURL));
ResolveInfo := SharedActivity.getPackageManager.resolveActivity(Intent, 0);
if ResolveInfo nil then
SharedActivity.startActivityForResult(Intent, FRequestCode);
finally
end;
end;
procedure TfrmmDropBoxIntent.HandleActivityMessage(const Sender: TObject; const M: TMessage);
begin
if M is TMessageResultNotification then
OnActivityResult(TMessageResultNotification(M).RequestCode, TMessageResultNotification(M).ResultCode,
TMessageResultNotification(M).Value);
end;
function TfrmmDropBoxIntent.OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean;
begin
Result := False;
TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, FMessageSubscriptionID);
FMessageSubscriptionID := 0;
if RequestCode = FRequestCode then
begin
//Get Data?
if Assigned(Data) then
begin
Memo1.Lines.Add(JStringToString(Data.getDataString));
end;
if ResultCode = TJActivity.JavaClass.RESULT_OK then
begin
if Assigned(Data) then
begin
//Get Data... How ?
end;
end
else if ResultCode = TJActivity.JavaClass.RESULT_CANCELED then
begin
//Cancel
end;
Result := True;
end;
end;