问题描述
我正在开发用于 HarmonyOS 应用程序开发的开源库,该库用于提示应用程序用户在应用程序库中对应用程序进行评级。为此,我需要实现一种方法来在用户同意提供反馈时启动应用程序库。对于Android,同样的功能是通过以下代码实现的
public void tryCollectingFeedback(@NonNull final Activity currentActivity,String packageName) {
String GOOGLE_PLAY_STORE_URI_PREFIX = "https://play.google.com/store/apps/details?id=";
try {
Uri uri = Uri.parse(GOOGLE_PLAY_STORE_URI_PREFIX + packageName);
currentActivity.startActivity(new Intent(ACTION_VIEW,uri));
} catch (final ActivityNotFoundException ignored) {
}
}
HarmonyOS 中的替代方案是什么?
解决方法
HarmonyOS API6 支持这一点。您可以使用模拟器进行测试。
以下是如何使用 API6 和示例代码进行测试:
public void tryCollectingFeedback( String packageName) {
String GOOGLE_PLAY_STORE_URI_PREFIX = "https://play.google.com/store/apps/details?id=";
Uri uri = Uri.parse(GOOGLE_PLAY_STORE_URI_PREFIX + packageName);
Intent intent = new Intent();
Operation op = new Intent.OperationBuilder()
.withAction(Intent.ACTION_VIEW_DATA)
.withUri(uri)
.build();
intent.setOperation(op);
startAbility(intent);
}
目前,API 6 只能在手机模拟器上运行。
使用 DevEco Studio 项目创建向导创建手机项目。 API为API 5,如果要使用API 6,可以修改项目如下:
-
根据creating and configuring a project的操作指南创建项目。
-
打开项目的
build.gradle
文件和模块的build.gradle
文件,修改项目支持的API版本。将compileSdkVersion
和compatibleSdkVersion
的值更改为 6。
ohos {
compileSdkVersion 6
defaultConfig {
compatibleSdkVersion 6
}
}
- 当前真机ROM版本不支持API 6。选择Use Remote Emulator to run applications,选择Mate30。