[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[jx8Intents] Select a contact


SwikiCodeRobot @> 582

"Select a contact"
| intent context |
context := MainActivity current.
intent := Intent action: Intent actionPick.
intent type: 'vnd.android.cursor.dir/contact'.
(intent resolveActivity: context packageManager) isNil ifTrue: [
	self error: 'Intent canīt be resolved'
].

context
	when: #onActivityResult:with:with:with:
	do: [:reqCode :resCode :intent :activity | 
		self print: 'intent=', intent.
		self print: 'reqCode=', reqCode asString, ' - ', 'resCode=', resCode asString.
		(reqCode = 1 and: [ resCode = -1 ]) ifTrue: [
		self print: 'contactUri=', intent data.
		" Do something with the selected contact at contactUri "
		]
	].
context startActivityForResult: intent requestCode: 1"REQUEST_SELECT_CONTACT".
^#Ok