Connect to Dropbox API using intents in Delphi Firemonkey

  

Recently I have got message from Dropbox:

Your Android app currently processes the OAuth app authorization flow inside a web view, instead of the system browser.

So I have to change the OAuth app authorization from TWebBrowser to Intents.

So here is my question. How can I get the data back from system browser and how to close the browser after authorization is finished?

I had tried with code below but I got “Cancelled” message only when I close the system browser.

My Code:

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;

Comments are closed.