From Delphi Demos Android Intents
procedure TForm1.SendTextViaIntent(const AText: string);
var
Intent: JIntent;
begin
Intent := TJIntent.Create;
Intent.setType(StringToJString('text/pas'));
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringToJString(AText));
if MainActivity.getPackageManager.queryIntentActivities(Intent,
TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size > 0 then
MainActivity.startActivity(Intent)
else
ShowMessage('Receiver not found');
end;
Enter topic text here.
SendIntent project has one source file, Unit1.pas.SendIntent application sends text using an intent. It uses the SendTextViaIntent procedure to create the intent object and start the activity for this intent.
procedure TForm1.SendTextViaIntent(const AText: string);
var
Intent: JIntent; //Declares the intent object
begin
Intent := TJIntent.Create;
Intent.setType(StringToJString('text/pas')); // Defines the data string.
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW); //Defines the Action.
Intent.putExtra(TJIntent.JavaClass.EXTRA_TEXT, StringtoJString(AText));
if MainActivity.getPackageManager.queryIntentActivities(Intent, TJPackageManager.JavaClass.MATCH_DEFAULT_ONLY).size > 0 then //Checks if there is at least one application capable of receiving the intent.
MainActivity.startActivity(Intent); //Calls startActivity() to send the intent to the system.
else
ShowMessage('Receiver not found');
end;
The primary pieces of information in an intent are:
•Action: the general action to be performed. In our sample, ACTION_VIEW.
•Data: the data to operate on, expressed as Uri. In our sample, 'text/pas'.
How Android Handles Incoming Intents (Android In >> Application Out)
•No app: If there are no apps on the device that can receive the implicit intent, the app crashes when it calls startActivity().Note: First verify that there is an app that can receive the intent.
•One app: When there is only one app that can handle the intent, the system immediately starts it.
•More than one app: If there is more than one app that can handle the activity, the system displays a dialog for the user to select which app to use.