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

test[jx8Intents] Capture Photo

SwikiCodeRobot @> 578

"Capture a picture or video and return it"
| context intent baseUri |
Intent ensurePermission: 'android.permission.CAMERA'.
baseUri := Uri parse: (Environment externalStoragePathName, MainActivity current defaultFolder). 
context := MainActivity current. 
intent := Intent action: 'android.media.action.IMAGE_CAPTURE'.
	putExtra: #output value: (Uri withAppendedPath: baseUri pathSegment: #newPhoto);
(intent resolveActivity: context packageManager) isNil ifTrue: [
	self error: 'Intent canīt be resolved'
	when: #onActivityResult:with:with:with:
	do: [:reqCode :resCode :data :activity | 
		(reqCode = 1 and: [resCode = -1]) ifTrue: [
		self print: 'OK!'.
context startActivityForResult: intent requestCode: 1.