From a2aaa3c00b18e2e11dceae9400cd6fc429562622 Mon Sep 17 00:00:00 2001 From: greenart7c3 <115044884+greenart7c3@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:10:25 -0300 Subject: [PATCH] add example of rememberLauncherForActivityResult --- 100.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/100.md b/100.md index 79ced802..24bf09f1 100644 --- a/100.md +++ b/100.md @@ -40,6 +40,24 @@ fun isExternalSignerInstalled(context: Context): Boolean { 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. +```kotlin +val launcher = rememberLauncherForActivityResult( + contract = ActivityResultContracts.StartActivityForResult(), + onResult = { result -> + if (result.resultCode != Activity.RESULT_OK) { + Toast.makeText( + context, + "Sign request rejected", + Toast.LENGTH_SHORT + ).show() + } else { + val signature = activityResult.data?.getStringExtra("signature") + // Do something with signature ... + } + } +) +``` + Create the Intent using the **nostrsigner** scheme: ```kotlin @@ -52,6 +70,12 @@ Set the Signer package name: intent.`package` = "com.example.signer" ``` +Send the Intent: + +```kotlin +launcher.launch(intent) +``` + ### Methods - **get_public_key**