-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add API for programmatic usage
- Loading branch information
1 parent
af2f6e1
commit 6766b98
Showing
6 changed files
with
90 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Léon can be called programmatically from other applications to clean URLs. | ||
Just like the user-facing application it is based on the standard mechanism of intents. | ||
|
||
To send text to Léon for cleaning, create an `Intent` with action `com.svenjacobs.app.leon.CLEAN` | ||
and put the text to clean as an extra with key `Intent.EXTRA_TEXT`. | ||
|
||
For Compose, use | ||
[rememberLauncherForActivityResult](https://developer.android.com/reference/kotlin/androidx/activity/compose/package-summary#rememberLauncherForActivityResult(androidx.activity.result.contract.ActivityResultContract,kotlin.Function1)) | ||
from `androidx.activity:activity-compose`. | ||
|
||
```kotlin | ||
val launcher = rememberLauncherForActivityResult( | ||
ActivityResultContracts.StartActivityForResult() | ||
) { result -> | ||
if (result.resultCode == Activity.RESULT_OK) { | ||
val cleanedText = result.data?.getStringExtra(Intent.EXTRA_TEXT) | ||
// Do something with cleanedText | ||
} | ||
} | ||
|
||
val intent = Intent("com.svenjacobs.app.leon.CLEAN").apply { | ||
putExtra(Intent.EXTRA_TEXT, "text to clean") | ||
} | ||
launcher.launch(intent) | ||
``` | ||
|
||
For legacy Android development you would use | ||
[startActivityForResult](https://developer.android.com/reference/android/app/Activity#startActivityForResult(android.content.Intent,%20int)) | ||
and the related API for Fragments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters