# Recognize image

Document Reader SDK provides the opportunity to recognize data from an image.

First of all, you need to check image browsing [permissions](/android/5.0-2/permissions.md).

Start Intent for getting image:

{% tabs %}
{% tab title="Java" %}

```java
// creates and starts image browsing intent
// results will be handled in onActivityResult method
private void createImageBrowsingRequest() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_BROWSE_PICTURE);
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// creates and starts image browsing intent
// results will be handled in onActivityResult method
private fun createImageBrowsingRequest() {
    val intent = Intent()
    intent.type = "image/*"
    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
    intent.action = Intent.ACTION_GET_CONTENT
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_BROWSE_PICTURE)
}
```

{% endtab %}
{% endtabs %}

Handle image browsing results:

{% tabs %}
{% tab title="Java" %}

```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) {
       //Image browsing intent processed successfully
        if (requestCode == REQUEST_BROWSE_PICTURE){
            if (data.getData() != null) {
                Uri selectedImage = data.getData();
                Bitmap bmp = getBitmap(selectedImage, 1920, 1080);

                DocumentReader.Instance().recognizeImage(bmp, completion);
             }
        }
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (resultCode == Activity.RESULT_OK) {
        //Image browsing intent processed successfully
        if (requestCode == REQUEST_BROWSE_PICTURE) {
            if (data!!.data != null) {
                val selectedImage = data.data
                val bmp = getBitmap(selectedImage, 1920, 1080)

                loadingDialog = showDialog("Processing image")

                DocumentReader.Instance().recognizeImage(bmp, completion)
            }
        }
    }
}
```

{% endtab %}
{% endtabs %}

Handle scan [results](/android/5.0-2/results/description-of-results.md):

{% tabs %}
{% tab title="Java" %}

```java
private DocumentReader.DocumentReaderCompletion completion = new DocumentReader.DocumentReaderCompletion() {
    @Override
    public void onCompleted(int action, DocumentReaderResults results, String error) {
        // processing is finished, all results are ready
        if (action == DocReaderAction.COMPLETE) { 
            // scanning process was finished
        }                
    } else {
        // something happened before all results were ready
        if (action == DocReaderAction.CANCEL){
            Toast.makeText(MainActivity.this, "Scanning was cancelled",Toast.LENGTH_LONG).show();
        } else if(action == DocReaderAction.ERROR){
            Toast.makeText(MainActivity.this, "Error:" + error, Toast.LENGTH_LONG).show();
        }
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
private val completion = DocumentReader.DocumentReaderCompletion { action, results, error ->
    // processing is finished, all results are ready
    if (action == DocReaderAction.COMPLETE) {
        // scanning process was finished
    } else {
        // something happened before all results were ready
        if (action == DocReaderAction.CANCEL) {
            Toast.makeText(this@MainActivity, "Scanning was cancelled", Toast.LENGTH_LONG).show()
        } else if (action == DocReaderAction.ERROR) {
            Toast.makeText(this@MainActivity, "Error:$error", Toast.LENGTH_LONG).show()
        }
    }
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://regulaforensics.gitbook.io/android/5.0-2/recognize-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
