Brian Long has a new comprehensive article up which covers launching activities and returning the result in Delphi XE6 Firemonkey on Android. Delphi XE6 has expanded functionality to get the results returned from an activity which was much more difficult to do in Delphi XE5. In addition to the activity results the article demonstrates how to show an Android Toast, show the Android battery usage screen, launch a URL, send an SMS, send an email, and launch a QR Scanner. The most important part of the article is the code demonstrating how to get results from the launched activity. Previously with the QR Scanner for example the tricky way to do it was via the Clipboard. Now with Delphi XE6 Firemonkey you can actually return and process the results of the startActivityForResult() Android API call. Here is a sample of the source code that starts the activity and then processes the results:
procedure TMainForm.BarcodeScannerButtonClick(Sender: TObject);
begin
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification,
HandleActivityMessage);
LaunchQRScanner(ScanRequestCode);
end;
procedure TMainForm.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 TMainForm.OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean;
var
ScanContent, ScanFormat: string;
begin
Result := False;
TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, FMessageSubscriptionID);
FMessageSubscriptionID := 0;
// For more info see https://github.com/zxing/zxing/wiki/Scanning-Via-Intent
if RequestCode = ScanRequestCode then
begin
if ResultCode = TJActivity.JavaClass.RESULT_OK then
begin
if Assigned(Data) then
begin
ScanContent := JStringToString(Data.getStringExtra(StringToJString('SCAN_RESULT')));
ScanFormat := JStringToString(Data.getStringExtra(StringToJString('SCAN_RESULT_FORMAT')));
Toast(Format('Found %s format barcode:'#10'%s', [ScanFormat, ScanContent]), LongToast);
end;
end
else if ResultCode = TJActivity.JavaClass.RESULT_CANCELED then
begin
Toast('You cancelled the scan', ShortToast);
end;
Result := True;
end;
end;
At the top of the article there is also a link to a similar article for Delphi XE5.
In delphi XE7 SharedActivity.startActivity(JIntent); not working in android apps. It is giving error while building the app. Can you please look into this and help us ?
And also TextPrompt (Water Marks) are not working in TEdits in android.
You can also just stick a TLabel inside of your TEdit and align it to Content or Client. Set it’s HitTest property to false. In the onChange event show it or hide it based on if the Text property is blank. TextPrompt had issues in previous versions too so I used this workaround instead.
But it is working fine in Delphi XE6 Update 1 ?
What about SharedActivity ? Please guide on this. Other wise shall we go back to the XE6 ?