- 浏览: 128543 次
- 性别:
- 来自: 武汉
-
文章分类
最新评论
-
酱油党:
你这个方法只能截当前activity,想要截取任意地方,怎么办 ...
全屏截图 -
月下独酌:
sxchao2008 写道/sdcard/cacerts.bk ...
android https之二 -
sxchao2008:
/sdcard/cacerts.bks 这个证书可以到网上随便 ...
android https之二 -
月下独酌:
Rhamiss 写道请问这是从sdcard安装ca证书的源代码 ...
android https之三 -
月下独酌:
Rhamiss 写道请问这是从sdcard安装ca证书的源代码 ...
android https之三
在应用程序中可以通过此工具类与android系统native服务通信
这些native服务是指在init.rc中定义的随机启动的服务,如zygote
但是如需要通过此工具类来启动和停止系统服务,需要具有system权限
即需要设置sharedUId=system
这些native服务是指在init.rc中定义的随机启动的服务,如zygote
但是如需要通过此工具类来启动和停止系统服务,需要具有system权限
即需要设置sharedUId=system
import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.net.vpn.VpnManager; import android.os.SystemProperties; import android.util.Log; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; class Command implements Serializable { private static final long serialVersionUID = 1L; private static final boolean DBG = true; private static final int WAITING_TIME = 15; // sec private static final String SVC_STATE_CMD_PREFIX = "init.svc."; private static final String SVC_START_CMD = "ctl.start"; private static final String SVC_STOP_CMD = "ctl.stop"; private static final String SVC_STATE_RUNNING = "running"; private static final String SVC_STATE_STOPPED = "stopped"; private static final int END_OF_ARGUMENTS = 255; private String mName; private String mTag; private transient LocalSocket mControlSocket; /** * Creates a proxy of the specified daemon. * @param daemonName name of the daemon */ UsbMacCommand(String daemonName) { mName = daemonName; mTag = "UsbMacCommand"; } void start() throws IOException { String svc = mName; if (DBG) Log.i(mTag, "Start usbmac native server " + svc); SystemProperties.set(SVC_START_CMD, svc); if (!blockUntil(SVC_STATE_RUNNING, WAITING_TIME)) { //if running if (DBG) Log.i(mTag, "cannot start service: " + svc); throw new IOException("cannot start service: " + svc); } else { mControlSocket = createServiceSocket(); } } int sendCommand(String ...args) throws IOException { if (DBG) Log.i(mTag,"sendCommand begin"); OutputStream out = getControlSocketOutput(); for (String arg : args) outputString(out, arg); out.write(END_OF_ARGUMENTS); out.flush(); int result = getResultFromSocket(true); if (DBG) Log.i(mTag,"sendCommand return:" + (char)result + "," + result); return result; } // returns 0 if nothing is in the receive buffer int getResultFromSocket() throws IOException { return getResultFromSocket(false); } void closeControlSocket() { if (mControlSocket == null) return; try { mControlSocket.close(); } catch (IOException e) { if (DBG) Log.w(mTag, "close control socket", e); } finally { mControlSocket = null; } } boolean stop() { String svc = mName; if (DBG) Log.i(mTag, "stop usbmac server: " + svc); SystemProperties.set(SVC_STOP_CMD, svc); boolean success = blockUntil(SVC_STATE_STOPPED, 5); if (DBG) Log.i(mTag, "stopping " + svc + " success = " + success); return success; } boolean isStopped() { String cmd = SVC_STATE_CMD_PREFIX + mName; return SVC_STATE_STOPPED.equals(SystemProperties.get(cmd)); } private int getResultFromSocket(boolean blocking) throws IOException { LocalSocket s = mControlSocket; if (s == null) return 0; InputStream in = s.getInputStream(); if (!blocking && in.available() == 0) return 0; int data = in.read(); return data; } private LocalSocket createServiceSocket() throws IOException { LocalSocket s = new LocalSocket(); LocalSocketAddress a = new LocalSocketAddress(mName, LocalSocketAddress.Namespace.RESERVED); // try a few times in case the service has not listen()ed IOException excp = null; for (int i = 0; i < 10; i++) { try { s.connect(a); return s; } catch (IOException e) { if (DBG) Log.w(mTag, "service not yet listen()ing; try again"); excp = e; sleep(500); } } throw excp; } private OutputStream getControlSocketOutput() throws IOException { if (mControlSocket != null) { return mControlSocket.getOutputStream(); } else { throw new IOException("no control socket available"); } } /** * Waits for the process to be in the expected state. The method returns * false if after the specified duration (in seconds), the process is still * not in the expected state. */ private boolean blockUntil(String expectedState, int waitTime) { String cmd = SVC_STATE_CMD_PREFIX + mName; int sleepTime = 200; // ms int n = waitTime * 1000 / sleepTime; for (int i = 0; i < n; i++) { if (expectedState.equals(SystemProperties.get(cmd))) { if (DBG) { Log.i(mTag, mName + " is " + expectedState + " after " + (i * sleepTime) + " msec"); } break; } sleep(sleepTime); } return expectedState.equals(SystemProperties.get(cmd)); } private void outputString(OutputStream out, String s) throws IOException { byte[] bytes = s.getBytes(); out.write(bytes.length); out.write(bytes); out.flush(); } private void sleep(int msec) { try { Thread.currentThread().sleep(msec); } catch (InterruptedException e) { throw new RuntimeException(e); } } }
发表评论
-
侧滑优化版本
2017-12-25 21:44 0import android.animation.Object ... -
RectRelativeLayout
2016-04-18 22:23 0package ui; import android.con ... -
ScrollView源码
2015-07-26 22:21 0package com.example.myapp.view; ... -
jumpToH5orNative
2015-06-09 17:48 0function jumpToH5orNative() { ... -
FloatWindowManager
2015-05-29 16:35 0package com.thestore.main.core. ... -
Activity亲和栈问题
2015-05-27 00:32 01、如果将要打开的目标Activity是SingleTask或 ... -
QQ5.0侧滑效果
2015-05-22 19:09 0package com.example.jobtest.qql ... -
水滴效果
2015-05-22 14:47 0package com.example.pluginmain; ... -
Android插件开发框架、源码、原理及重点介绍
2015-05-04 17:23 4123https://github.com/limpoxe/Andr ... -
android 动态加载 插件开发 可以加载插件资源文件
2014-06-17 15:27 0android 动态加载 插件开发 可以加载插件资源文件 -
android https之四
2012-10-16 17:05 0private static String[] printC ... -
时间格式化
2012-10-12 14:49 0Locale.setDefault(new Locale( ... -
webview
2012-10-08 10:35 0package com.android.test; im ... -
popUp window
2012-09-21 13:15 0// 创建一个包含自定义view的PopupWindow ... -
ViewPager
2012-09-05 12:00 0package com.android.test; ... -
PinnedHeaderListView
2012-09-05 11:48 0/* * Copyright (C) 2007 The ... -
滑动切屏的指示器
2012-08-01 10:38 0/* * Copyright (C) 2011 Pat ... -
listview 长度自适应
2012-07-27 17:14 0import android.view.View; im ... -
滑动切屏 slidelayout launcher workspace
2012-07-25 18:36 0import android.content.Contex ... -
android定位
2012-07-24 15:57 0private static String getLo ...
相关推荐
通过Socket.io与Node.js进行React Native通信的工作演示。这是在采用另一个项目之前将RN应用程序与Socket.io链接的试验。 怎么跑 Node.js服务器: 需要Node.js,Express.js,Socket.io,Ngrok CD服务器 DEBUG =...
React-native-chat-app 使用socket.ioReact本机简单聊天应用程序。 截屏 聊天画面 服务器入门 要获得有关Socket.io入门的帮助,请查看在线。 1. 2.克隆存储库 $ ...
You’ll also build server-side code for a mobile React Native app to talk to using the popular Node.js and Socket.io library, providing you a holistic view of things even beyond React Native....
React-Native-Chat-App
Native、Flutter等,非原生框架,性能上都会或多或少的折损。但各个框架,都会做出性能提升建议,所以开发者在开发前,多了解一下,后面维护升级等就会更方便一点,否则项目越来越大,后续开发就会越来越难。现在...
Android应用与framework的socket通信示例
My-React-Native-App 基于expo搭建的React Native+Node.js+ts仿闲鱼(项目代号:闲猪)项目 技术栈 前端采用ts,基于搭建(通用的React应用程序框架和平台,围绕React Native和native平台的工具集),表单采用,状态...
该存储库涵盖了使用React Native和MERN堆栈实现的3个主要平台的主要是Android,IOS和Web :fire: 。您可以在此存储库中看到以下功能正在运行, 即时和实时文本一对一聊天用户的在线/离线可用性上次查看时间未读邮件...
使用React和socket.io聊天应用程序这个应用程序是基本的聊天应用程序,不包含数据库,它是React和socket.io的重点开始安装 git clone ... 有两个文件需要正确如下src / components / Main.js --->...
speedy-im 该项目已停止更新,由于项目无需支持小程序以及 H5,故使用 React-Native 进行重构,并将项目拆分重构,新项目功能更完整,性能更佳。 新项目请查看
目录构建世博会的“独立”应用从Create React Native App弹出构建依赖关系(Xcode和Android Studio) 我应该使用ExpoKit吗? 故障排除联网iOS模拟器无法打开QR码不扫描 更新到新版本您只需要很少(理想情况下永远不...
该示例已移至。 这是一个示例程序,显示了如何使用从... 编辑app.py和app_mysql.py的unix_socket ,以指向与您在步骤1中使用的应用程序相关联的Cloud SQL实例。 上载应用: appcfg.py update .贡献变化参见发牌参见
我尝试使用mongo,express,React-native,node.js和socket.io创建实时聊天应用程序 具有各种功能的全栈式社交媒体应用程序:完整的CRUD功能(您可以创建,搜索,过滤,编辑和删除用户帐户,消息,公共聊天室,私人...
AirbnbClone关于这个项目该项目是Airbnb的克隆Web和移动设备,使用React,React Native,Node和实时Socket.io构建关于这个项目的一些观察该项目是我个人投资的一部分,我正在尝试提高自己的技能,因此,如果您能提供...
网络通讯属于基础&业务框架层中基础设施的一部分,为App提供统一的网络服务:Native模块是携程的核心业务模块(酒店、机票、火车票、攻略等),Native模块的网络服务主要通过TCP连接实现,而非常见的RestfulHTTPAPI...
RN聊天使用React Native,Nativepaper,nodejs,express js和socket io制作的聊天室应用程序。使用的图书馆带有React Hooks,NativeBase和express的React Native React Navigation 4.0,Redux,Redux Thunk 插座io 4...
react-native-starter-kit该项目是一个自定义的入门工具包,只需单击一下即可构建TypeScript react-native应用程序。另外,您可以通过添加模板来为项目做出贡献。 :glowing_star:特征使用TypeScript或Javascript快速...
B4A - The simplest way to develop real-world, native Android apps! B4A includes all the features needed to quickly develop any type of Android app. ... Remote compilation mode (only available in the ...
前端开发是创建WEB页面或APP等前端界面呈现给用户的过程,通过HTML、CSS及JavaScript以及衍生出来的各种技术、框架、解决方案,来实现互联网产品的用户界面交互。 前端开发从网页制作演变而来,名称上有很明显的...