最近リリースされた GDK のカードを使用すると問題が発生します。基本的に、Card.addImage() は、リソース ID または URI の 2 つの引数しか取ることができません。
私のユースケースでは、リソースとして直接ではなく、ファイルとして存在する画像を開く必要があります。したがって、テスト目的で、アセットフォルダーに画像を含めています。アセットフォルダから直接アクセスしようとすると失敗するので、そこから内部ストレージにコピーしています。コピーしたら、ファイルから URI を生成し、それをカードに割り当てます。結果のカードには、画像があるべき場所に灰色のブロックが表示されます。
String fileName = step.attachment; //of the form, "folder1/images/image1.jpg"
File outFile = new File(getFilesDir()+File.separator+fileName);
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
//check to see if the file has already been cached in internal storage before copying
if(!outFile.exists()) {
FileInputStream inputStream = new FileInputStream(getAssets().openFd(fileName).getFileDescriptor());
FileOutputStream outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
inputChannel = inputStream.getChannel();
outputChannel = outputStream.getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try {
if(inputChannel!=null)
inputChannel.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if(outputChannel!=null)
outputChannel.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
card.addImage(Uri.fromFile(outFile));
カードが内部で何をしているのかわからないため、診断するのは困難です。