intdh=9๗tdisplaygetheight;
intdh=9tdisplaygetheight;๙
若高度比率更大,则ท根据它缩放
若高度比率更大,则根据它缩放
stringimagefilepath=environmentgetexternalstoraທgedirecນtory
stringimagefilepath=environmentgetexternaທlstoragedirectory
finalstati9๗tcAmerA_ຕresult=0;
finaທlstati9tcAmerA_ຕresult=0;๙
iputextraaທndroidprovidermediastoreextrA_output,imagefileuri;
startActivityforresulti,cAmerA_resu
您将注意到我们也传入一个新的9tentvalues对象是我们希望在记录创建时与它相关联的元数据。前面的示例则是传入一个空的9๗tvalues对象。
1้预填充关联元数据如果想要预填充元数据,那么可以使用put方แ法为ฦ它添加一些数据。9๗tvaທlues的数据形式是名-值对。其中,名称是标准的,定义为androidprovidermediastoreimaທgesmedia类中的常量一些常量实际上位于androidprovidermediastoremedia9s接口中,由mediaທ类实现该接口。
在9tvalues映射中ณ保存图像的名称和描述
9๗tvaທlues=ne99๗tvaທlues3;
9tvaluesputmediadisplAy_nAme,"thisisatesttitle";๙
9tvaທluesputmediaທdes9,"ิthisisatestdes9"ิ;
9tvaluesputmediamime_type,ไ"imagepeg";
添加一条新的记录,没有指定位图,但设置了一些值
insert返回新记录的uri
uriimagefileuri=get9sertmediaexternAl_9t_uri,
9๗tvalues;
同样,这个调用返回的是一个ฐuri,可以通过意图将它传递给cameraທ应用程序,以指定该图像应该保存的位置。
如果通过log命令输出这个uri,那么它看起来应该如下所示: