# \[Android]チャットの画像アップロードに対応する

チャットの接客サービスでは画像のアップロードを行うことが可能です。

なおアプリ側で独自に管理しているWebView上にチャットを表示する場合（Webページに埋め込まれている計測タグを使ってチャットを出す場合）に限り、事前に実装を行う必要があります。

SDK側で管理するWebView上にチャットを表示するケースでは、実装は不要です。

## 実装方法（サンプル）

[WebChromeClient](https://developer.android.com/reference/android/webkit/WebChromeClient) の `onShowFileChooser` メソッドを実装します。

{% code title="MainActivity.java" overflow="wrap" %}

```java
private final static int FILE_CHOOSER_REQUEST_CODE = 1;
private ValueCallback<Uri[]> mFilePathCallback;

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // ...
  webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
      mFilePathCallback = filePathCallback;

      Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
      intent.setType("image/*");
      intent.addCategory(Intent.CATEGORY_OPENABLE);
      startActivityForResult(intent, FILE_CHOOSER_REQUEST_CODE);
      returu true;
    }
  });
}

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

  if (requestCode == FILE_CHOOSE_REQUEST_CODE) {
    if (resultCode == RESULT_OK) {
      mFilePathCallback.onReceiveValue(new Uri[] { data.getData() });
    } else {
      mFilePathCallback.onReceiveValue(null);
    }
    mFilePathCallback = null;
  }
}
```

{% endcode %}


---

# 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://app.developers.karte.io/android-sdk-appendix/appendix-chat-image-upload-android-sdk.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.
