티스토리 뷰
RADStudio10.4Demos/Object Pascal/Mobile Snippets/AndroidIntents at master · Embarcadero/RADStudio10.4Demos
Delphi and C++Builder Demos for Embarcadero RAD Studio version 10.4 - Embarcadero/RADStudio10.4Demos
github.com
----------------------------------------------------------------------------------------------------------
<!-- ✅ OAuth2 Redirect (딥링크 수신용) -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="letterbridge"
android:host="oauth2redirect" />
</intent-filter>
----------------------------------------------------------------------------------------------------------
FMX.Android Intents Sample
This demo shows interaction between Android applications using intents. It consists of two applications, SendIntent that creates and send the intent, and ReceiveIntent that receives the intent and displays the information.
- 1 Location
- 2 Description
- 3 How to Use the Sample
- 4 Implementation
- 4.1 SendIntent
- 4.1.1 How Android Handles Incoming Intents
- 4.2 ReceiveIntent
- 4.2.1 Modifying the AndroidManifest.xml
- 5 Uses
- 6 See Also
You can find the Android Intents sample project at:
- Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to:
- C:\Users\Public\Documents\Embarcadero\Studio\Samples\Object Pascal\Mobile Snippets\AndroidIntents
- GitHub Repository:
- For Delphi: https://github.com/Embarcadero/RADStudio10.4Demos/tree/master/Object%20Pascal/Mobile%20Snippets/AndroidIntents/
This sample demonstrates how to register an Android intent action.
- On the sender:
- Defines the intent type with <intent_name>.setType().
- Defines the intent action with <intent_name>.setAction(TJIntent.JavaClass.ACTION_VIEW).
- Calls startActivity() when there is at least one application capable of receiving the intent.
- On the receiver you need to register the type of intent action that you want your application to be able to receive.
- Calls registerIntentAction(TJIntent.JavaClass.ACTION_VIEW). Same action as in the sender.
- Registers the receiver in the Android Manifest file. A corresponding </code> and <code><action></code> tags must exist in the <code><intent-filter></code> section.
- Navigate to the location given above.
- Open the sample application group project file: AndroidIntentsGroup.groupproj.
- Select ReceiveIntent on the Projects Window.
- Select the Android device on the Project Manager.
- Press F9 or choose Run > Run.**Note:**ReceiveIntent needs to be on the device to receive the broadcast information.
- Select SendIntent on the Project Manager.
- Select the Android device on the Project Manager.
- Press F9 or choose Run > Run. Note: Send both applications to the same Android device, otherwise you need to use push notifications.
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'. The application has two TButton:
- TButton1 sends the text to write a simple Hello World Delphi application. It calls SendTextViaIntent procedure with the text as a parameter, on the OnClick event.
- TButton2 sends the structure of a Delphi .pas file in the same way as TButton1.
- 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.
ReceiveIntent project has one source file, Unit1.pas. It receives and shows the text from the SendIntent application.
- HandleIntentAction function verifies that the intent contains information and shows the text on the TMemo1.
- HandleAppEvent function verifies that the intent is not null and calls HandleIntentAction function with the received itent. This function handles the intent the first time ReceiveIntent opens.
- ReceiveIntent procedure handles the intent when ReceiveIntent is already open. The itent is register using MainActivity.registerIntentAction(TJIntent.JavaClass.ACTION_VIEW);.To receive simple data from other applications, you need to update the Android Manifest file to create the intent filters that are necessary to receive intents for a specific action. After editing the Android Manifest for a specific action, when SendIntent application tries to share the information passing the intent to startActivity(), ReceiveIntent appears as the option to view this information. If more than one options is available, an app chooser with all the apps appears.
Modify the Android Manifest xml file to add the intent filter. An intent filter informs the Android system about what intents the application can accept. In this example, an intent filter is added to accept the intent created on the SendIntent application. The ReceiveIntent is the only application that can accept the intent from SendIntent application. The application that receives the intent needs to add some tags to the Android Manifest.
- After building your project for the first time with Android selected on the Projects Window, the AndroidManifest.template.xml is added to your project folder.
- Edit the AndroidManifest.template.xml file to add the following lines:
<!--<%application-meta-data%>
...
<activity android:name="com.embarcadero.firemonkey.FMXNativeActivity"
android:label="%activityLabel%"
android:configChanges="orientation|keyboard|keyboardHidden"
android:launchMode="singleTask">
...-->
<intent-filter>
...
<action android:name="android.intent.action.VIEW" /> <!--Constant Value for the ACTION_VIEW-->
<category android:name="android.intent.category.DEFAULT" /> <!-- Activities that want to receive implicit intents must include this constant-->
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/pas" /> <!--Sets the MIME type of your intent.-->
</intent-filter>
<!--</activity>-->
The sample uses Built-in Java libraries for Android.
- Androidapi.JNI.GraphicsContentViewText
- Androidapi.JNI.App
- Androidapi.Helpers
- FMX.Platform.Android
- Androidapi.JNI.JavaTypes
- Androidapi.JNI.Net
- Androidapi.JNI.Os
- Using the Built-in RAD Studio Java Libraries for Android
- Intents and Intent Filters
- CATEGORY_BROWSABLE
- CATEGORY_DEFAULT
- Preparing an Android Application for Deployment#Customizing Your AndroidManifest.xml File
- Android Application Manifest File (AndroidManifest.xml)
- Verify There is an App to Receive the Intent
- Total
- Today
- Yesterday
- 솔로몬시스템
- 솔로원DB복제
- 비에이블스터디카페
- Could not convert variant of type (Null) into type (OleStr)
- SOLO1ASP
- push server
- 안드로이드_관리자
- Unable to load project
- KSNetPOSLib.ocx
- 스터디카페
- Android 64
- Firemonkey
- KSNetPOSLib
- 앱관리자
- DelphiZeroMQ
- 안드로이드관리자
- TT쿼리
- 키오스크
- delphi push message
- WidevineID
- Delphi
- RADStudio11
- mysql db 복구
- FMX
- Grijjy
- solomonsystem
- READ_PRIVILEGED_PHONE_STATE
- .dproj
- 비에이블
- 식권발매
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |