Android - 检查commitContent图像键盘支持

问题描述:

我正在使用图像键盘。Android - 检查commitContent图像键盘支持

一直在这里跑来跑去,看着Image Keyboard Support,以及相关类的文档。我成功地能够检查MIME类型(在本例中为image/gif),但我不认为它表示输入能够接受丰富的内容。我需要这个,所以我可以运行回退来分享图片。

的“我不认为它的指示输入的能够接受丰富的内容”发生在我的最后一个使用案例:

  • 默认邮件应用程序:未检测到图像/ GIF支持,图像 键盘功能被禁用。
  • Google环聊:检测到图片/ gif支持, 和我选择的gif图片成功发布。
  • Slack:检测到image/gif支持, InputConnectionCompat.commitContent()返回true,但没有图像 发布。

如何验证目标应用程序中是否接受了丰富的内容?

Hi You can verify by the following method 

private boolean isCommitContentSupported(@NonNull String mimeType) { 
     if (getCurrentInputEditorInfo() == null) { 
      return false; 
     } 

     final InputConnection ic = getCurrentInputConnection(); 
     if (ic == null) { 
      return false; 
     } 

     if (!validatePackageName(getCurrentInputEditorInfo())) { 
      return false; 
     } 

     final String[] supportedMimeTypes = EditorInfoCompat.getContentMimeTypes(getCurrentInputEditorInfo()); 
     for (String supportedMimeType : supportedMimeTypes) { 
      if (ClipDescription.compareMimeTypes(mimeType, supportedMimeType)) { 
       return true; 
      } 
     } 
     return false; 
    }