int permissionCheck = ContextCompat.checkSelfPermission(ImageKitRenderDemoActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
initData();
initImageRender();
} else {
ActivityCompat.requestPermissions(ImageKitRenderDemoActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}
如果已有权限,或权限申请成功后,对Image渲染模块进行初始化
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// The permission is granted.
initData();
initImageRender();
} else {
// The permission is rejected.
Log.w(TAG, "permission denied");
Toast.makeText(ImageKitRenderDemoActivity.this, "Please grant the app the permission to read the SD card", Toast.LENGTH_SHORT).show();
}
}
}
Image渲染模块初始化
获取渲染实例,初始化,并获取渲染视图。 这里会指定动画元素的目录:
ImageRender.getInstance(context, new ImageRender.RenderCallBack() {
// 获取场景动效服务实例成功回调,返回场景动效服务实例
@Override
public void onSuccess(ImageRenderImpl imageRender) {
imageRenderAPI = imageRender;
if (imageRenderAPI != null) {
int initResult = imageRenderAPI.doInit(sourcePath, Utils.getAuthJson());
Log.i(TAG, "DoInit result == " + initResult);
if (initResult == 0) {
// Obtain the rendered view.
RenderView renderView = imageRenderAPI.getRenderView();
if (renderView.getResultCode() == ResultCode.SUCCEED) {
View view = renderView.getView();
if (null != view) {
// Add the rendered view to the layout.
contentView.addView(view);
hashCode = String.valueOf(view.hashCode());
} else {
Log.w(TAG, "GetRenderView fail, view is null");
}
}
}
// 获取场景动效服务实例失败回调,返回错误码
@Override
public void onFailure(int errorCode) {
...
}
});