Android SDK Samples - Photos and Attachments Operations
//$record object is of ZCRMRecord
//call getAttachments() using $record object by passing the page, perPage and modifiedSince as parameters.
//page - page number of the attachments
//perPage - no of attachments to be given for a single page.
//modifiedSince - filter only those modified since the given time
$record.getAttachments(3,20,"2020-08-06T16:23:24+05:30",object:DataCallback<BulkAPIResponse,List<ZCRMAttachment>>
{
override fun completed(response: BulkAPIResponse, zcrmentity: List<ZCRMAttachment>) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception:$exception")
}
})
//$record object is of ZCRMRecord
//call uploadLinkAsAttachment() using $record object by passing the url as a parameter to it
//url - url of the attachment
$record.uploadLinkAsAttachment("https://abc.com",object:DataCallback<APIResponse,ZCRMAttachment>
{
override fun completed(response: APIResponse, zcrmentity: ZCRMAttachment) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception:$exception")
}
})
//$record object is of ZCRMRecord
//call uploadAttachment() using $record object by passing the fileRequestRefId and uri as parameters to it
//fileRequestRefId - reference id which is used as a tag to this api request
//uri - Uri of the resource which is to be uploaded
$record.uploadAttachment("123456789",uriSource,object : FileWithDataTransferTask<APIResponse, ZCRMAttachment>{
override fun onCompletion(response: APIResponse, attachment: ZCRMAttachment) {
println("${response.responseJSON}")
}
override fun onFailure(exception: ZCRMException) {
println("Throws Exception : $exception ")
}
override fun onProgressUpdate(bytesWritten: Long, contentLength: Long, percentage: Double) {
println("$bytesWritten, $contentLength, $percentage")
}
})
//$record object is of ZCRMRecord
//call uploadAttachment() using $record object by passing the fileRequestRefId and filePath as parameters to it.
//fileRequestRefId - reference id which is used as a tag to this api request
//filePath - file path of the attachment
$record.uploadAttachment("123456789",File(filename).absolutePath,object : FileWithDataTransferTask<APIResponse,ZCRMAttachment>{
override fun onCompletion(response: APIResponse, attachment: ZCRMAttachment) {
println("${response.responseJSON}")
}
override fun onFailure(exception: ZCRMException) {
println("Throws Exception : $exception")
}
override fun onProgressUpdate(bytesWritten: Long, contentLength: Long, percentage: Double) {
println("OnProgress Update : $bytesWritten, $contentLength, $percentage")
}
})
//$record object is of ZCRMRecord
//call downloadAttachment() using $record object by passing the fileRequestRefId, filePath, fileName and id.
//fileRequestRefId - reference id which is used as a tag to this api request
//filePath - path where the file should be downloaded
//fileName - name of the file should be downloaded
//id - Id of the attachment to be downloaded
$record.downloadAttachment("1234569841",File(filename).absolutePath, "sales_report.pdf",371xxx007, object: DataCallback<FileAPIResponse,InputStream>{
override fun completed(response: FileAPIResponse, inputStream: InputStream) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})
//$record object is of ZCRMRecord
//call deleteAttachment() using $record object by passing it as a parameter to it.
//id - Id of the attachment to be deleted
$record.deleteAttachment(371xxx007, object : ResponseCallback<APIResponse>{
override fun completed(response: APIResponse) {
println(" ${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})
//$record object is of ZCRMRecord
//call uploadPhoto() using $record object by passing the fileRequestRefId and filePath as parameters to it.
//fileRequestRefId - reference id which is used as a tag to this api request
//filePath - file path of the photo
$record.uploadPhoto("123458767", File(filename).absolutePath, object :FileTransferTask<APIResponse>
{
override fun onCompletion(response: APIResponse) {
println("${response.responseJSON}")
}
override fun onFailure(exception: ZCRMException) {
println("Throws Exception : $exception")
}
override fun onProgressUpdate(bytesWritten: Long, contentLength: Long, percentage: Double) {
println("$bytesWritten, $contentLength, $percentage")
}
})
File file = new File(Filename);
Uri uriSource = FileProvider.getUriForFile(applicationcontext, "com.example.android.fileprovider", file);
//$record object is of ZCRMRecord
//call uploadPhoto() using $record object by passing fileRequestRefId and uri as parameters to it.
//fileRequestRefId - reference id which is used as a tag to this api request
//uri - Uri of the resource which is to be uploaded
$record.uploadPhoto(123458767,uriSource,object:FileTransferTask<APIResponse>{
override fun onCompletion(response: APIResponse) {
println("${response.responseJSON}")
}
override fun onFailure(exception: ZCRMException) {
println("Throws Exception : $exception")
}
override fun onProgressUpdate(bytesWritten: Long, contentLength: Long, percentage: Double) {
println("$bytesWritten, $contentLength, $percentage")
}
})
//$record object is of ZCRMRecord
//call deletePhoto() using $record object
$record.deletePhoto(object : ResponseCallback<APIResponse>{
override fun completed(response: APIResponse) {
println("${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})
//$record object is of ZCRMRecord
//call downloadPhoto() using $record object
$record.downloadPhoto(object : DataCallback<FileAPIResponse, InputStream>{
override fun completed(response: FileAPIResponse, inputStream: InputStream) {
println(" ${response.responseJSON}")
}
override fun failed(exception: ZCRMException) {
println("Throws Exception : $exception")
}
})