diff options
| author | greenart7c3 <115044884+greenart7c3@users.noreply.github.com> | 2024-03-18 15:10:25 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-18 15:10:25 -0300 |
| commit | a2aaa3c00b18e2e11dceae9400cd6fc429562622 (patch) | |
| tree | ac9853eb35052888d398646181907a474e849ad2 /100.md | |
| parent | 6b26ebe6c5c9834549aa9adec0d066bc5c6aae88 (diff) | |
add example of rememberLauncherForActivityResult
Diffstat (limited to '100.md')
| -rw-r--r-- | 100.md | 24 |
1 files changed, 24 insertions, 0 deletions
| @@ -40,6 +40,24 @@ fun isExternalSignerInstalled(context: Context): Boolean { | |||
| 40 | 40 | ||
| 41 | To get the result back from the Signer Application you should use `registerForActivityResult` or `rememberLauncherForActivityResult` in Kotlin. If you are using another framework check the documentation of your framework or a third party library to get the result. | 41 | To get the result back from the Signer Application you should use `registerForActivityResult` or `rememberLauncherForActivityResult` in Kotlin. If you are using another framework check the documentation of your framework or a third party library to get the result. |
| 42 | 42 | ||
| 43 | ```kotlin | ||
| 44 | val launcher = rememberLauncherForActivityResult( | ||
| 45 | contract = ActivityResultContracts.StartActivityForResult(), | ||
| 46 | onResult = { result -> | ||
| 47 | if (result.resultCode != Activity.RESULT_OK) { | ||
| 48 | Toast.makeText( | ||
| 49 | context, | ||
| 50 | "Sign request rejected", | ||
| 51 | Toast.LENGTH_SHORT | ||
| 52 | ).show() | ||
| 53 | } else { | ||
| 54 | val signature = activityResult.data?.getStringExtra("signature") | ||
| 55 | // Do something with signature ... | ||
| 56 | } | ||
| 57 | } | ||
| 58 | ) | ||
| 59 | ``` | ||
| 60 | |||
| 43 | Create the Intent using the **nostrsigner** scheme: | 61 | Create the Intent using the **nostrsigner** scheme: |
| 44 | 62 | ||
| 45 | ```kotlin | 63 | ```kotlin |
| @@ -52,6 +70,12 @@ Set the Signer package name: | |||
| 52 | intent.`package` = "com.example.signer" | 70 | intent.`package` = "com.example.signer" |
| 53 | ``` | 71 | ``` |
| 54 | 72 | ||
| 73 | Send the Intent: | ||
| 74 | |||
| 75 | ```kotlin | ||
| 76 | launcher.launch(intent) | ||
| 77 | ``` | ||
| 78 | |||
| 55 | ### Methods | 79 | ### Methods |
| 56 | 80 | ||
| 57 | - **get_public_key** | 81 | - **get_public_key** |