val keyguardManager =
getSystemService(KEYGUARD_SERVICE) as KeyguardManager
keyguardManager.requestDismissKeyguard( this, object :
KeyguardDismissCallback() { override fun onDismissError() { // Unlock failed.
Dismissing keyguard is not feasible. } override fun onDismissSucceeded() { //
Unlock succeeded. Device is now unlocked. } override fun onDismissCancelled()
{ // Unlock failed. User cancelled operation or request otherwise cancelled. }
} )
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
result: ActivityResult -> if (result.resultCode ==
Intent.CAPTURE_CONTENT_FOR_NOTE_SUCCESS) { val uri = result.data?data // Use
the URI to paste the captured content into the note. } }
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Create a note-taking app\n\nNote-taking is a core capability of Android that enhances user productivity on\nlarge screen devices. Note‑taking apps enable users to write and sketch in\na floating window or on the full screen, capture and annotate screen content,\nand save notes for later review and revision.\n\nUsers can access note-taking apps from the lock screen or while running other\napps.\n\nStylus support for note-taking provides an exceptional user experience.\n\nNotes role\n----------\n\nThe\n[`RoleManager.ROLE_NOTES`](/reference/kotlin/android/app/role/RoleManager#role_notes)\nrole identifies note‑taking apps and grants them the\n[`LAUNCH_CAPTURE_CONTENT_ACTIVITY_FOR_NOTE`](/reference/android/Manifest.permission#LAUNCH_CAPTURE_CONTENT_ACTIVITY_FOR_NOTE)\npermission.\n\nTo acquire the notes role for your app, do the following:\n\n1. Call [`isRoleAvailable()`](/reference/kotlin/android/app/role/RoleManager#isroleavailable) to check the status of the role.\n2. If the notes role is available, call [`createRequestRoleIntent()`](/reference/kotlin/android/app/role/RoleManager#createrequestroleintent) to obtain a notes‑specific intent.\n3. Call [`startActivityForResult()`](/reference/kotlin/android/app/Activity#startactivityforresult) with the notes intent to prompt the user to grant the notes role to your app.\n\nOnly one app can possess the notes role.\n\nThe app opens in response to an implicit\n[`ACTION_CREATE_NOTE`](/reference/kotlin/android/content/Intent#action_create_note)\nintent action. If invoked from the device lock screen, the app opens full\nscreen; if invoked while the screen is unlocked, in a floating window.\n| **Note:** In system settings, users can opt out of having a default note‑taking app, in which case no app responds to the `ACTION_CREATE_NOTE` intent action.\n\nApp manifest\n------------\n\nTo qualify for the notes role, your app must include the following declaration\nin the app manifest: \n\n \u003cactivity\n android:name=\"YourActivityName\"\n android:exported=\"true\"\n android:showWhenLocked=\"true\"\n android:turnScreenOn=\"true\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.CREATE_NOTE\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n\nThe declaration enables users to assign the notes role to your app, making it\nthe default note‑taking application:\n\n- [`ACTION_CREATE_NOTE`](/reference/kotlin/android/content/Intent#action_create_note)\n sets the intent action to which your app responds\n\n- [`showWhenLocked`](/reference/kotlin/android/R.attr#showwhenlocked)\n makes your app accessible from the device lock screen\n\n- [`turnScreenOn`](/reference/kotlin/android/R.attr#turnscreenon) enables\n your app to turn the device screen on when the app runs\n\nApp features\n------------\n\nA large screen differentiated note‑taking app provides a full complement\nof note‑taking capabilities.\n\n### Stylus support\n\nWhen your app is invoked with the\n[`EXTRA_USE_STYLUS_MODE`](/reference/kotlin/android/content/Intent#extra_use_stylus_mode)\nintent extra set to `true`, the app should open a note that accepts stylus (or\nfinger-touch) input.\n\nIf the intent extra is set to `false`, your app should open a note that accepts\nkeyboard input.\n\n### Lockscreen access\n\nYour app must provide a full‑screen activity that runs when the app is\nopened from the device lock screen.\n\nYour app should show only historical notes if the user has consented (in the\nunlocked device state) to showing past notes. Otherwise, when opened from the\nlock screen, your app should always create a new note.\n\nYou can check whether your app has been launched from the lock screen with\n[`KeyguardManager#isKeyguardLocked()`](/reference/android/app/KeyguardManager#isKeyguardLocked()).\nTo ask the user to authenticate and unlock the device, call\n[`KeyguardManager#requestDismissKeyguard()`](/reference/android/app/KeyguardManager#requestDismissKeyguard(android.app.Activity,%20android.app.KeyguardManager.KeyguardDismissCallback)):\n\n\u003cbr /\u003e\n\n val keyguardManager =\n getSystemService(KEYGUARD_SERVICE) as KeyguardManager\n keyguardManager.requestDismissKeyguard( this, object :\n KeyguardDismissCallback() { override fun onDismissError() { // Unlock failed.\n Dismissing keyguard is not feasible. } override fun onDismissSucceeded() { //\n Unlock succeeded. Device is now unlocked. } override fun onDismissCancelled()\n { // Unlock failed. User cancelled operation or request otherwise cancelled. }\n } )\n\n| **Warning:** When launched from the device lock screen, your app must ensure user privacy.\n\n### Floating windows\n\nFor contextual note-taking, your app must provide an activity that opens in a\nfloating window when another application is running.\n\nYour app should support\n[`multi-instance`](/develop/ui/compose/layouts/adaptive/support-multi-window-mode#multi-instance)\nmode so that users can create multiple notes in multiple floating windows even\nwhen your note‑taking app is launched full screen or in split‑screen\nmode.\n\n### Content capture\n\nContent capture is a key capability of note‑taking apps. With content\ncapture, users can take screenshots of the display behind the note‑taking\napp's floating window. Users can capture all or part of the display, paste the\ncontent into their note, and annotate or highlight the captured content.\n\nYour note-taking app should provide a UI affordance that launches an\n[`ActivityResultLauncher`](/reference/kotlin/androidx/activity/result/ActivityResultLauncher)\ncreated by\n[`registerForActivityResult()`](/reference/kotlin/androidx/activity/result/ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract,androidx.activity.result.ActivityResultCallback)).\nThe\n[`ACTION_LAUNCH_CAPTURE_CONTENT_ACTIVITY_FOR_NOTE`](/reference/kotlin/android/content/Intent#action_launch_capture_content_activity_for_note)\nintent action is provided to the launcher either directly or through an\n[`ActivityResultContract`](/reference/kotlin/androidx/activity/result/contract/ActivityResultContract).\n\nA system activity captures the content, saves it on the device, and returns the\ncontent URI to your app in the callback argument of\n`registerForActivityResult()`.\n\nThe following example uses a generic\n[`StartActivityForResult`](/reference/kotlin/androidx/activity/result/contract/ActivityResultContracts.StartActivityForResult)\ncontract:\n\n\u003cbr /\u003e\n\n private val startForResult =\n registerForActivityResult( ActivityResultContracts.StartActivityForResult()) {\n result: ActivityResult -\u003e if (result.resultCode ==\n Intent.CAPTURE_CONTENT_FOR_NOTE_SUCCESS) { val uri = result.data?.data // Use\n the URI to paste the captured content into the note. } } override fun\n onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)\n setContent { NotesTheme { Surface(color =\n MaterialTheme.colorScheme.background) { CaptureButton( onClick = {\n Log.i(\"ContentCapture\", \"Launching intent...\")\n startForResult.launch(Intent(ACTION_LAUNCH_CAPTURE_CONTENT_ACTIVITY_FOR_NOTE))\n }) } } } } @Composable fun CaptureButton(onClick: () -\u003e Unit) {\n Button(onClick = onClick)\n {Text(\"Capture Content\")} }\n\nYour app should handle all result codes:\n\n- [`CAPTURE_CONTENT_FOR_NOTE_SUCCESS`](/reference/android/content/Intent#CAPTURE_CONTENT_FOR_NOTE_SUCCESS)\n- [`CAPTURE_CONTENT_FOR_NOTE_FAILED`](/reference/android/content/Intent#CAPTURE_CONTENT_FOR_NOTE_FAILED)\n- [`CAPTURE_CONTENT_FOR_NOTE_USER_CANCELED`](/reference/android/content/Intent#CAPTURE_CONTENT_FOR_NOTE_USER_CANCELED)\n- [`CAPTURE_CONTENT_FOR_NOTE_WINDOW_MODE_UNSUPPORTED`](/reference/android/content/Intent#CAPTURE_CONTENT_FOR_NOTE_WINDOW_MODE_UNSUPPORTED)\n- [`CAPTURE_CONTENT_FOR_NOTE_BLOCKED_BY_ADMIN`](/reference/android/content/Intent#CAPTURE_CONTENT_FOR_NOTE_BLOCKED_BY_ADMIN)\n\nWhen content capture succeeds, paste the captured image into the note, for\nexample:\n\n\u003cbr /\u003e\n\n registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {\n result: ActivityResult -\u003e if (result.resultCode ==\n Intent.CAPTURE_CONTENT_FOR_NOTE_SUCCESS) { val uri = result.data?data // Use\n the URI to paste the captured content into the note. } }\n\nThe content capture feature should be exposed through a UI affordance only when\nyour note‑taking app is running in a floating window---not when\nrunning full screen, launched from the device lock screen. (Users can take\nscreenshots of the note‑taking app itself with device screenshot\ncapabilities.)\n\nTo determine whether your app is in a floating window (or bubble), call the\nfollowing methods:\n\n- [`isLaunchedFromBubble()`](/reference/kotlin/android/app/Activity#islaunchedfrombubble) to check that your note‑taking app was not launched full screen from the device lock screen\n- [`isRoleHeld(RoleManager.ROLE_NOTES)`](/reference/kotlin/android/app/role/RoleManager#isroleheld) to verify that your app is the default note‑taking app (your app can run in a conversation or other type of bubble if the app does not hold the notes role)\n\n| **Note:** Your app should check whether content capture is permitted by device administrative policies. Call [`getScreenCaptureDisabled()`](/reference/kotlin/android/app/admin/DevicePolicyManager#getscreencapturedisabled) with `null` as the argument.\n\nAdditional resources\n--------------------\n\n- [Get a result from an activity](/training/basics/intents/result)"]]