赞
踩
换设备,找一台能跳转的设备。具体原因还不知道。
代码写的不一定规范,且不说更新的问题,这个只是在测试跳转。
DevEco Studio 3.0.0.993 Release
SDK 6(使用java)
package com.openvally.cyj;
import com.openvally.cyj.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
public class MainAbility extends Ability {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setMainRoute(MainAbilitySlice.class.getName());
}
}
package com.openvally.cyj; import com.openvally.cyj.slice.Pay2AbilitySlice; import com.openvally.cyj.slice.PayAbilitySlice; import ohos.aafwk.ability.Ability; import ohos.aafwk.content.Intent; import ohos.hiviewdfx.HiLog; import ohos.hiviewdfx.HiLogLabel; public class PayAbility extends Ability { @Override public void onStart(Intent intent) { super.onStart(intent); super.setMainRoute(PayAbilitySlice.class.getName()); addActionRoute(); } //添加路由 private void addActionRoute(){ addActionRoute("action.pay2", Pay2AbilitySlice.class.getName()); } }
package com.openvally.cyj.slice; import com.openvally.cyj.PayAbility; import com.openvally.cyj.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.aafwk.content.Operation; import ohos.agp.components.Component; import ohos.agp.components.Text; import ohos.agp.utils.LayoutAlignment; import ohos.agp.window.dialog.ToastDialog; import ohos.utils.IntentConstants; public class MainAbilitySlice extends AbilitySlice { @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main); toPayAbility(); toPay2Ability(); toDialPage(); } //跳转到payAbility private void toPayAbility(){ Text text_to_payAbility = (Text)findComponentById(ResourceTable.Id_text_to_payAbility); text_to_payAbility.setClickedListener(listen -> { new ToastDialog(getContext()) .setText("test1") .setAlignment(LayoutAlignment.CENTER) .show(); Intent intentSend = new Intent(); Operation operation = new Intent.OperationBuilder() .withDeviceId("") .withBundleName(getBundleName()) .withAbilityName(PayAbility.class.getName()) .build(); intentSend.setOperation(operation); startAbility(intentSend); }); } //跳转到pay2Ability private void toPay2Ability() { Text text_to_pay2Ability = (Text) findComponentById(ResourceTable.Id_text_to_pay2Ability); text_to_pay2Ability.setClickedListener(listen ->{ new ToastDialog(getContext()) .setText("test2") .setAlignment(LayoutAlignment.CENTER) .show(); Intent intentSend = new Intent(); Operation operation = new Intent.OperationBuilder() .withAction("action.pay2") .build(); intentSend.setOperation(operation); startAbility(intentSend); }); } //跳转到拨号页面 private void toDialPage() { Text text_to_pay2Ability = (Text) findComponentById(ResourceTable.Id_text_to_dialPage); text_to_pay2Ability.setClickedListener(listen ->{ new ToastDialog(getContext()) .setText("test3") .setAlignment(LayoutAlignment.CENTER) .show(); Intent intentSend = new Intent(); Operation operation = new Intent.OperationBuilder() .withAction(IntentConstants.ACTION_DIAL) .build(); intentSend.setOperation(operation); startAbility(intentSend); }); } @Override public void onActive() { super.onActive(); } @Override public void onForeground(Intent intent) { super.onForeground(intent); } }
package com.openvally.cyj.slice; import com.openvally.cyj.PayAbility; import com.openvally.cyj.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.hiviewdfx.HiLog; import ohos.hiviewdfx.HiLogLabel; public class PayAbilitySlice extends AbilitySlice { @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_pay); } @Override public void onActive() { super.onActive(); } @Override public void onForeground(Intent intent) { super.onForeground(intent); } }
package com.openvally.cyj.slice; import com.openvally.cyj.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; public class Pay2AbilitySlice extends AbilitySlice { @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_pay2); } @Override public void onActive() { super.onActive(); } @Override public void onForeground(Intent intent) { super.onForeground(intent); } }
<?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos" ohos:height="match_parent" ohos:width="match_parent" ohos:alignment="center" ohos:orientation="vertical"> <Text ohos:id="$+id:text_to_payAbility" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="精确跳转到PayAbility" ohos:text_size="30vp" /> <Text ohos:id="$+id:text_to_pay2Ability" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="模糊跳转到Pay2Ability" ohos:text_size="30vp" /> <Text ohos:id="$+id:text_to_dialPage" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="跳转到DialPage" ohos:text_size="30vp" /> </DirectionalLayout>
<?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos" ohos:height="match_parent" ohos:width="match_parent" ohos:alignment="center" ohos:orientation="vertical"> <Text ohos:id="$+id:text_payAbility" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="This is PayAbility" ohos:text_size="30vp" /> </DirectionalLayout>
<?xml version="1.0" encoding="utf-8"?> <DirectionalLayout xmlns:ohos="http://schemas.huawei.com/res/ohos" ohos:height="match_parent" ohos:width="match_parent" ohos:alignment="center" ohos:orientation="vertical"> <Text ohos:id="$+id:text_payAbility" ohos:height="match_content" ohos:width="match_content" ohos:layout_alignment="horizontal_center" ohos:text="This is Pay2Ability" ohos:text_size="30vp" /> </DirectionalLayout>
{ "app": { "bundleName": "com.openvally.cyj", "vendor": "example", "version": { "code": 1000000, "name": "1.0.0" } }, "deviceConfig": { }, "module": { "package": "com.openvally.cyj", "name": ".MyApplication", "mainAbility": "com.openvally.cyj.MainAbility", "deviceType": [ "phone", "tablet" ], "distro": { "deliveryWithInstall": true, "moduleName": "entry", "moduleType": "entry", "installationFree": false }, "abilities": [ { "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "action.system.home" ] } ], "name": "com.openvally.cyj.MainAbility", "description": "$string:mainability_description", "icon": "$media:icon", "label": "$string:entry_MainAbility", "launchType": "standard", "orientation": "unspecified", "visible": true, "type": "page" }, { "skills": [ { "actions": [ "action.pay2" ] } ], "name": "com.openvally.cyj.PayAbility", "description": "$string:payability_description", "icon": "$media:icon", "label": "$string:entry_PayAbility", "launchType": "standard", "orientation": "unspecified", "visible": true, "type": "page" } ] } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。