ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

鸿蒙开发经验教训

2021-10-16 19:35:29  阅读:272  来源: 互联网

标签:String 鸿蒙 经验教训 entities 开发 intent new com Intent


 

  • WebView的resource response

 

//                    Uri requestUri = request.getRequestUrl();
// String urltrytoload = requestUri.toString();
// if (CheckNetworkStatus.isNetworkConnectedInternet(getContext()) == false) {
//// HiLog.info(mLogLabel, webView.getComponentDescription().toString()+"webViewInFocus ResourceResponse processResourceRequest NOT %{public}s,编号为%{public}d", requestUri.toString(), 123456);
// String response = "";
//// "<html>\n" +
//// "<center><div style=\"width:270px;height:60px;border:0px solid grey;\">"+
//// "<p><font size=\"3\" face=\"arial\" color=\"red\"><center>网址不可达,请检查网络状态!</center></font></p>"+
//// "</div></center>"+
//// "<html>";
// ResourceResponse webResourceResponse = new ResourceResponse("text/html", new ByteArrayInputStream(response.getBytes()), "utf-8");
// HiLog.error(HLQQ, webView.getComponentDescription().toString()+"webViewInFocus webResourceResponse %{public}s,编号为%{public}d", webResourceResponse.getCharset() + webResourceResponse.getReason(), 123480);
//
//// threadtoupdateUi(1);
//
// return webResourceResponse;
//
//
// } else {
// HiLog.error(HLQQ, webView.getComponentDescription().toString()+"webViewInFocus ResourceResponse processResourceRequest YES %{public}s,编号为%{public}d", requestUri.toString(), 123457);
// return super.processResourceRequest(webView, request);
// }



  • 拦截并处理本地资源

                //此段代码有用,用于处理本地文件。不要删除!

// @Override
// public ResourceResponse processResourceRequest(WebView webview, ResourceRequest request) {
//
//
// final String authority = "lingxihelp.com";
// final String rawFile = "/rawfile/";
// final String local = "/local/";
// Uri requestUri = request.getRequestUrl();
// if (authority.equals(requestUri.getDecodedAuthority())) {
// String path = requestUri.getDecodedPath();
// if (TextTool.isNullOrEmpty(path)) {
// return super.processResourceRequest(webview, request);
// }
// if (path.startsWith(rawFile)) {
// // 根据自定义规则访问资源文件
// String rawFilePath = "entry/resources/rawfile/" + path.replace(rawFile, "");
// String mimeType = URLConnection.guessContentTypeFromName(rawFilePath);
// try {
// Resource resource = getResourceManager().getRawFileEntry(rawFilePath).openRawFile();
// ResourceResponse response = new ResourceResponse(mimeType, resource, null);
// return response;
// } catch (IOException e) {
// HiLog.info(mLogLabel, "open raw file failed");
// }
// }
// if (path.startsWith(local)) {
// // 根据自定义规则访问本地文件
// String localFile = getContext().getFilesDir() + path.replace(local, "/");
// HiLog.info(mLogLabel, "open local file " + localFile);
// File file = new File(localFile);
// if (!file.exists()) {
// HiLog.info(mLogLabel, "file not exists");
// return super.processResourceRequest(webview, request);
// }
// String mimeType = URLConnection.guessContentTypeFromName(localFile);
// try {
// InputStream inputStream = new FileInputStream(file);
// ResourceResponse response = new ResourceResponse(mimeType, inputStream, null);
// return response;
// } catch (IOException e) {
// HiLog.info(mLogLabel, "open local file failed");
// }
// }
// }
// return super.processResourceRequest(webview, request);
// }

 

  • 以schedule方式run

//                        HiLog.warn(HLQQ, "++++++++++updateprogress");
// progress2 = newValue;
// timerTask2 = new TimerTask() {
// @Override
// public void run() {
// myEventHandlerBoundwithmainrunner.sendEvent(12);
// }
// };
// timer2 = new Timer();
// timer2.schedule(timerTask2, 1000, 1000);

 

  • ClipBoard

        SystemPasteboard pasteboard = SystemPasteboard.getSystemPasteboard(this);
PasteData pasteData = new PasteData();
pasteData.addTextRecord("转自外媒-:" + wv.getTitle() + wv.getFirstRequestUrl());
// PacMap pacMap = new PacMap();
// pacMap.putString("ADDITION_KEY", "ADDITION_VALUE_OF_TEXT");
// pasteData.getProperty().setAdditions(pacMap);
// pasteData.getProperty().setTag("USER_TAG");
// pasteData.getProperty().setLocalOnly(true);
pasteboard.setPasteData(pasteData);
// pasteData = null;


  • 启动各种各样的Intent


// Intent intent = new Intent();
// Operation operation = new Intent.OperationBuilder().withAction("android.intent.action.GET_CONTENT").build();
// intent.addFlags(Intent.FLAG_NOT_OHOS_COMPONENT);
// intent.setType("text/plain");
// intent.setOperation(operation);
// startAbility(intent);

// Intent intent = new Intent();
// Set<String> entities = new HashSet<>();
// entities.add("android.intent.category.LAUNCHER");
// Operation operation = new Intent.OperationBuilder()
// .withDeviceId("")
// .withBundleName("com.tencent.mm")
// .withAbilityName("com.tencent.mm.ui.LauncherUI")
// .withAction("android.intent.action.MAIN")
// .withFlags(Intent.FLAG_NOT_OHOS_COMPONENT)
// .withEntities(entities)
// .build();
// intent.setOperation(operation);
// startAbility(intent);


// IBundleManager manager = this.getBundleManager();
// try {
// System.out.println("QQQQQQQQQQQQQQQQQQQQQQQQQQQ"+manager.getAllFormsInfo().toArray().toString());
// } catch (RemoteException e) {
// e.printStackTrace();
// }

// Intent intent = new Intent();
// intent.setType("text/plain");
// Set<String> entities = new HashSet<>();
// entities.add("android.intent.category.LAUNCHER");
// Operation operation = new Intent.OperationBuilder()
// .withDeviceId("")
//// IT's ok'
//// .withBundleName("com.autonavi.minimap")
//// .withAbilityName("com.autonavi.map.activity.SplashActivity")
//// .withBundleName("com.sina.weibo")
// //这是启动页
//// .withAbilityName("com.sina.weibo.SplashActivity")
// //这是功能页
//// .withAbilityName("com.sina.weibo.MainTabActivity")
// //这是写微博的地方。
//// .withAbilityName("com.sina.weibo.composerinde.OriginalComposerActivity")
// .withAction("android.intent.action.MAIN")
// .withFlags(Intent.FLAG_NOT_OHOS_COMPONENT)
// .withEntities(entities)
// .build();
// intent.setOperation(operation);
// startAbility(intent);

// outsideIntent = new Intent();
//// intent.setType("text/plain");
// Set<String> entities = new HashSet<>();
// entities.add("android.intent.category.LAUNCHER");
//// entities.add("android.intent.category.DEFAULT");
//// entities.add("android.intent.category.HOME");
// Operation operation = new Intent.OperationBuilder()
// .withDeviceId("")
// .withBundleName("com.huawei.android.internal.app")
// .withAbilityName("com.huawei.android.internal.app.instantshare.HwInstantShareActivity")
// .withAction("android.intent.action.MAIN")
// .withFlags(Intent.FLAG_NOT_OHOS_COMPONENT)
// .withEntities(entities)
// .build();
// outsideIntent.setOperation(operation);
// startAbility(outsideIntent);

// private boolean isAppExist(Context context, String appPkg) {
// manager = context.getBundleManager();
// if (verifySelfPermission("ohos.permission.GET_BUNDLE_INFO_PRIVILEGED") != IBundleManager.PERMISSION_GRANTED) {
// // 应用未被授予权限
// if (canRequestPermission("ohos.permission.GET_BUNDLE_INFO_PRIVILEGED")) {
// // 是否可以申请弹框授权(首次申请或者用户未选择禁止且不再提示)
// requestPermissionsFromUser(
// new String[]{"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"}, 9090);
// } else {
// // 显示应用需要权限的理由,提示用户进入设置授权
// new ToastDialog(getContext()).setText("请进入系统设置进行授权").show();
// }
// } else {
//
// }
// return true;
//

  • PopDiglog版toast

private void manyToast(String textshown) {

DirectionalLayout webToastLayoutforsoftkeyforward = (DirectionalLayout) LayoutScatter.getInstance(getContext())
.parse(ResourceTable.Layout_web_toast_xward, null, false);
((Text) webToastLayoutforsoftkeyforward.getComponentAt(0)).setText(textshown);
((Text) webToastLayoutforsoftkeyforward.getComponentAt(0)).setFont(Font.DEFAULT_BOLD);
webToastLayoutforsoftkeyforward.setBackground(elementToast);
PopupDialog toastMadeMyself = new PopupDialog(getContext(), networkNotAvailablePage);
toastMadeMyself.setCustomComponent(webToastLayoutforsoftkeyforward);
toastMadeMyself.setDuration(1000);
toastMadeMyself.setCornerRadius(160);
toastMadeMyself.showOnCertainPosition(LayoutAlignment.TOP, 0, 320);
toastMadeMyself.show();
}
  • 各种更新UI的方法

调用主UI线程异步和延时异步、定时间隔、通过进程间通讯事件

 

 

 

 

 

 

 

标签:String,鸿蒙,经验教训,entities,开发,intent,new,com,Intent
来源: https://www.cnblogs.com/augustone/p/15415007.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有