安卓java端service如何在native进程进行访问-跨进程通讯高端知识

2026年.NET/C#就业前景与实战学习路线全解析 在软件开发领域,编程语言和框架的选择直接影响开发者的职业发展路径。从技术原理上看,现代开发平台的核心竞争力在于跨平台能力、性能表现和生态成熟度。.NET通过开源与跨平台重构,实现了从Windows生态到全平台支持的技术跃迁,其价值体现在高性能运行时、云原生友好性以及丰富的应用场景覆盖上。特别是在企业级应用、云服务和高性能Web API等场景中,.NET Core及后续版本展现出卓越的工程实践价值。本文聚焦.NET技术栈的就业前景,结合云原生和微服务等行业热点,为开发者剖析2026年的市场需求,并提供从基础到 阅读详情

背景:

近来有学员朋友在马哥vip群里提出关于跨进程相关的问题,具体问题如下:
想要在纯native进程中获取当前android系统有多个display,然后获取每个display的Id。但是这个获取display的数目和id的接口其实是在systemserver进程的DisplayManagerService里面。
在这里插入图片描述
目前很多系统服务,比如wms,ams,display都是java形式作为服务端运行在systemserver,正常客户端访问肯定也是用java相关接口进行调用。但是今天需求就是需要使用native进程来跨进程访问到systemserver的DisplayManagerService。
在这里插入图片描述
简单总结需求:
需要在纯native只有c++代码的进程中跨进程访问systemserver的DisplayManagerService相关的接口getDisplayIds。
这里其实我们在跨进程通迅专题课程中有讲解过类似native和java端的相互调用情况,当时的案例是服务端是native的,客户端是java的情况
,相信大家只要实战过马哥跨进程通讯课程肯定就对这个题目有自己的思路和方案。

思路设计和参考

因为跨进程通讯本质上都是需要通过native端,虽然服务端或者客户端是java端,那都是先经过了native端再jni调用到java的,所以完全是可以实现客户端和服务端不要求两个都属于native或者java,完全可以native和java互通。
但是这个需求是要调用到DisplayManagerService的java接口,native因为不可以调用java,也就无法直接使用aidl生成的java接口。那么具体该怎么写这个native端调用服务端的接口呢?这里就需要我们拿aidl文件生成的java文件来参考,看看这个java文件是如何实现的跨进程通讯。

上一篇文章
aosp系统源码aidl文件如何查看对应生成的java文件-安卓系统开发实战小技巧分享
已经分享了如何查看系统中aidl文件对应的java文件,这里我们展示一下我们要访问的DisplayManagerService的getDisplayIds相关方法详情:

 private static class Proxy implements android.hardware.display.IDisplayManager
    {
//省略部分
      @Override public int[] getDisplayIds(boolean includeDisabled) throws android.os.RemoteException
      {
        android.os.Parcel _data = android.os.Parcel.obtain();
        android.os.Parcel _reply = android.os.Parcel.obtain();
        int[] _result;
        try {
          _data.writeInterfaceToken(DESCRIPTOR);
          _data.writeBoolean(includeDisabled);
          boolean _status = mRemote.transact(Stub.TRANSACTION_getDisplayIds, _data, _reply, 0);
          _reply.readException();
          _result = _reply.createIntArray();
        }
        finally {
          _reply.recycle();
          _data.recycle();
        }
        return _result;
      }

可以从上面这个java的Proxy端即客户端看出,调用一个跨进程接口getDisplayIds,本质上套路如下:
1、parcel对象会包装好相关的传递数据
2、需要知道跨进程调用的方法的code,这里的话是Stub.TRANSACTION_getDisplayIds,这里的

static final int TRANSACTION_getDisplayIds = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);

其实就是一个整数,这里是一般根据aidl编写方法的上到下顺序生成

3、调用transact方法把上面准备的parcel,code,_reply带上,这样数据到了远端就可以根据code找到对应的实现方法,同时通过parcel获取相关参数,也可以写回相关数据到_reply

4、读取跨进程返回的_reply相关数据

分析到这里我们就有了一个很清晰思路,那就要针对native端使用c++代码写出和上面客户端跨进程访问服务端代码。

实战开发:

代码参考就是上面Proxy的的getDisplayIds方法,然后变成c++形式而已,整体的流程属性,和parcel包装都可以完全参考java的,这里其实核心代码就是以下几行:

_data.writeInterfaceToken(DESCRIPTOR);
_data.writeBoolean(includeDisabled);
boolean _status = mRemote.transact(Stub.TRANSACTION_getDisplayIds, _data, _reply, 0);
_reply.readException();
_result = _reply.createIntArray();

首先就是writeInterfaceToken方法:
frameworks/base/core/java/android/os/Parcel.java

public final void writeInterfaceToken(@NonNull String interfaceName) {
        nativeWriteInterfaceToken(mNativePtr, interfaceName);
    }

frameworks/base/core/jni/android_os_Parcel.cpp

static void android_os_Parcel_writeInterfaceToken(JNIEnv* env, jclass clazz, jlong nativePtr,
                                                  jstring name)
{
    Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
    if (parcel != nullptr) {
        InterfaceDescriptorString descriptor(env, name);
        parcel->writeInterfaceToken(reinterpret_cast<const char16_t*>(descriptor.str()),
                                    descriptor.size());
    }
}

最后调用到Parcel.cpp
在这里插入图片描述
可以看出本质就是writeString16
writeBoolean
frameworks/base/core/java/android/os/Parcel.java

 public final void writeBoolean(boolean val) {
        writeInt(val ? 1 : 0);
    }

就是直接writeInt

readException

frameworks/base/core/java/android/os/Parcel.java

   public final void readException() {
        int code = readExceptionCode();
        if (code != 0) {
            String msg = readString();
            readException(code, msg);
        }
    }
     public final int readExceptionCode() {
        int code = readInt();
			//省略异常情况
        return code;
    }

也就是正常情况readException也就是readInt()获取一个返回int值而已

createIntArray

还有差异的就是java端的_reply.createIntArray()代码c++没有,这里就需要进去看看它的具体实现:
frameworks/base/core/java/android/os/Parcel.java

    @Nullable
    public final int[] createIntArray() {
        int N = readInt();//首先读取数组大小
        ensureWithinMemoryLimit(SIZE_INT, N);
        if (N >= 0 && N <= (dataAvail() >> 2)) {
            int[] val = new int[N];
            for (int i=0; i<N; i++) {
                val[i] = readInt();//然后读取int放入数组
            }
            return val;
        } else {
            return null;
        }
    }

有了上面的这些转化后,写出native的如下代码:

#define LOG_TAG "Main"

#include <android-base/logging.h>
#include <android-base/properties.h> 
#include <binder/IBinder.h>
#include <binder/Parcel.h>
#include <binder/IServiceManager.h>

#include <utils/Log.h>
#include <utils/threads.h>
#include "MyThread.h"
 
using namespace android;
void testNativeCallJavaServer() {
	android::sp<android::IServiceManager> sm = android::defaultServiceManager();
	android::sp<android::IBinder> binder = sm->checkService(android::String16("display"));
	if (binder == nullptr) {
		ALOGV("Failed to get display service.");
		std::cerr << "Failed to get display service." << std::endl;
		return;
	}

	android::Parcel _aidl_data;
	_aidl_data.markForBinder(binder);
	_aidl_data.writeInterfaceToken(android::String16("android.hardware.display.IDisplayManager"));
	_aidl_data.writeInt32(1);

	android::Parcel _aidl_reply;
	int TRANSACTION_getDisplayIds = 2;//代码1
	android::status_t _aidl_ret_status = binder->transact(TRANSACTION_getDisplayIds, _aidl_data, &_aidl_reply);
	if (_aidl_ret_status != android::NO_ERROR) {
		std::cerr << "Transact failed with status: " << _aidl_ret_status << std::endl;
		return;
	}

	int32_t resultCode;
	if (_aidl_reply.readInt32(&resultCode) != android::NO_ERROR || resultCode != 0) {
		std::cerr << "Error in response or non-zero resultCode." << std::endl;
		return;
	}

	size_t count = _aidl_reply.readInt32();//读取
	std::cerr << "Number of displays: " << count << std::endl;
	for (size_t i = 0; i < count; ++i) {
		int32_t displayId;
		if (_aidl_reply.readInt32(&displayId) == android::NO_ERROR) {
			std::cerr << "Display ID: " << displayId << std::endl;
		} else {
			std::cerr << "Failed to read displayId at index " << i << std::endl;
		}
	}
}

代码1处的int TRANSACTION_getDisplayIds = 2,注意这里的2就是从aidl对应的java文件中获得的,所有这个就是为啥要一定要找一个aidl文件生成的参考代码。

验证成果:

NX563J:/ # android_thread                                                                                                                                                                                         
Number of displays: 2
Display ID: 0
Display ID: 2


运行后输出当前display有2个,id分别0和2.

更多framework实战技术干货,请关注下面“千里马学框架”

androidjni编程,java和c层的互相通信传递数据 android开发之jni开发,java层native层之间的相互调用,方便广大学者工作者学习参考 立即下载

相关推荐

OpenEarthMap 与 xBD 数据集合并

整合好的数据:链接: https://pan.baidu.com/s/1uJ_Zg6n-s3u1D49OW52D7Q?pwd=2vwx 提取码: 2vwx完整整合步骤与代码如下。

qq_60293814的博客 1596

Android多进程和跨进程通讯方式

进程间通信(InterProcess Communication缩写IPC)是指在不同进程之间传播或交换信息。进程是一个具有一定独立功能的程序关于某个数据集合的一次运行活动。它是操作系统动态执行的基本单元。Android多进程和跨进程通讯方式有几种方式?

hirezy 3021

钉钉开发(三)——Java推送钉钉待办任务

之前一篇博文中,讲解了如何推送钉钉群消息,感兴趣的可以点击查看。 钉钉开发(一)——Java给钉钉群推送消息

Monten_Cristo的博客 6412

Android系统源码分析-进程间通信机制binder(四):从Native层到Driver层

本篇继续分析Android Binder机制相关源代码,主要从Native(c++)层到driver层的相关组件已经代码调用流程。

记录和分享程序人生的点点滴滴 8360

避坑指南:Qt5.14.2 ARM交叉编译中那些你可能遇到的‘坑’及解决方案

本文深度解析了Qt 5.14.2在ARM架构上进行交叉编译的完整流程与常见难题。重点阐述了如何精准匹配交叉编译器与目标板环境、正确配置sysroot以及使用configure参数的艺术,并针对编译过程中的头文件缺失、链接错误等典型“坑”提供了经过验证的解决方案,旨在帮助开发者成功构建适用于嵌入式设备的Qt运行时库。

weixin_29279101的博客 355

全网最全-QCC51xx-QCC30xx(TWS)系列从入门到精通开发教程汇总(持续更新中)

QCC3040开发笔记之基本介绍(0) QCC3040开发笔记之开发环境搭建(1) QCC3040开发笔记之debug调试(trb调试,usbt调试,adb调试,WIFI调试)(2) QCC3040开发笔记之按键配置(3) QCC3040开发笔记之按键切换(4) QCC3040开发笔记之按键逻辑(5) QCC3040开发笔记之tone(6) QCC3040开发笔记之提示音(7) QCC3040开发笔记之bitserial接口(8) QCC3040开发笔记之双mic+AEC+ANC(9...

心跳包的博客 3万+

Android跨进程通信,binder,native层,服务端在servicemanager注册服务

服务端代码binder_open利用系统调用函数打开驱动,然后调用svcmgr_publish组装binder_io数据结构体,binder_call去调用驱动,在这个过程中,binder_io结构体会转换为binder_write_read给binder驱动,然后servicemanager进程也会通过binder_write_read读取服务端传递过来的数据,binder_loop,servicemanager启动后,收到服务注册的通知,binder_call远程调用。//给上面的结构体赋值数据。

weixin_46039528的博客 788

第一部分:VTK基础入门(第1章:VTK简介与概述)

VTK简介与核心特性概述 VTK(Visualization Toolkit)是一个开源的跨平台C++类库,专用于3D计算机图形学、图像处理和科学可视化。由Kitware公司开发,VTK自1993年起源以来,经历了开源化、成熟化和现代化多个发展阶段,现已成为科学可视化的核心工具之一。 VTK的核心特性包括: 管道架构:模块化设计实现数据流管理 丰富的数据支持:处理多边形数据、图像数据等 强大的渲染能力:集成OpenGL,支持多种渲染技术 最新版本VTK 9.4.2增强了现代C++支持,优化了内存管理,并提升

仰望星空的博客 2363

Android Java层与Native通信踩过的坑

前言:2014-05-08记录在hi baidu上,现在移过来 如果通信的双方都是E文,那么这所有的问题就比较好解决,但遇到多字节语言时情况就不那么乐观了。

夏天夏天悄悄过去留下小眯眯 1895

AUTOSAR-SOMEIP配置总结

导入arxml之后someip信号一般以“pduSomeIp”开头或者“SomeIp”开头。以某个pdu为例,设置项“Pdu Default Partition Ref”主要是根据模块设计,配置相应的Ecuc核分区。在导入arxml之后someip信号中有三个特殊的信号,形如“SdInstance”开头的信号,设置项“Pdu Default Partition Ref”主要是根据模块设计,配置相应的Ecuc核分区。“EcuC”模块主要关注“EcucPduCollection”中的“Pdus”下面的配置。

xiandang8023的博客 4655

AutoClip AI视频剪辑工具:Docker一键部署指南

摘要:AutoClip是一个基于Docker容器化部署的智能视频剪辑系统,采用微服务架构设计,包含Web界面、后端API、异步任务处理和Redis缓存等组件。系统支持一键快速部署,提供完整的监控和日志功能,最低要求4GB内存和10GB存储空间。部署过程仅需三个步骤:克隆代码、配置环境变量、启动容器服务。生产环境支持性能调优、数据持久化和网络安全管理。该系统解决了环境配置难题,实现"一次配置,到处运行"的目标,适合需要自动化视频处理的用户。

wjianwei666的专栏 1011

Android-Native进程间通信实例—Socket本地通信服务端进程异常退出解决办法(1)

如果你觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。,第一时间获取最新知识点Android架构师之路很漫长,一起共勉吧!这次面试问的还是还是有难度的,要求当场写代码并且运行,也是很考察面试者写代码因为Android知识体系比较庞大和复杂的,涉及到计算机知识领域的方方面面。在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。

2401_84123113的博客 1041

自动驾驶算法-滤波器系列(三)——不同运动模型(CV、CA、CTRV、CTRA)的建模和推导

CV & CA & CTRV & CTRA1. CV模型2. CA模型3. CTRV模型4. CTRA模型 1. CV模型 2. CA模型 3. CTRV模型 4. CTRA模型

weixin_41480034的博客 2万+

Android应用开发为何是初创企业的增长杠杆

原生移动应用是数字业务落地的核心载体,其本质是将用户交互、数据资产与操作系统能力深度整合的技术基础设施。基于Android平台的开放性、硬件兼容性与全球市场覆盖率,它能支撑高留存、低跳出、强触达的闭环体验,显著提升订阅转化率与订单完成率。尤其在LBS服务、后台任务调度、系统级通知及离线AI能力(如ML Kit)等场景中,Android展现出远超Web和跨平台方案的工程确定性与技术纵深。对初创企业而言,一次规范的Android开发实践,不仅是上线一个App,更是倒逼业务流程数字化、用户路径可度量、运营动作自动

weixin_30596165的博客 423

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

C/S与B/S架构深度解析:从原理到选型,一次讲透两种经典模式

在软件架构领域,客户端/服务器(C/S)和浏览器/服务器(B/S)是两种基础且广泛应用的模式。C/S架构通过安装在用户设备上的独立客户端程序,充分利用本地计算资源,实现高性能的图形渲染、实时数据处理和离线操作,其核心在于“能力前置”。而B/S架构则以浏览器作为统一客户端,所有业务逻辑集中于服务器,实现了零安装部署、跨平台访问和便捷的集中更新,其设计哲学是“集中管控”。从技术价值看,C/S适合对性能、实时性及本地硬件交互有严苛要求的场景,如专业设计软件、工业控制和游戏;B/S则凭借其极低的部署维护成本和极广的

weixin_33724059的博客 478

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

android native c java进行本地socket通信----java服务端 C客户端

方式一:java做服务器端,native做client端1. 建立java应用程序,建立Server 类* Copyright (C) 2009 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file ex

hgm770876501的专栏 703

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Binder源码分析之Java层(原)

前面的几节中我们介绍了Native层Binder通讯的原理和用法,那么在Java层如何使用Binder通讯呢?其原理又与Native层的Binder有什么关系呢?         与Native层的ServiceManager类似,Android在Java层也有一个ServiceManager用于处理Java层Service的注册、申请。只不过,Java层的这个ServiceManager,其实

阿杜的专栏 3976

JAVA中的native是什么

1、一个native方法就是一个Java调用非Java代码的接口。一个native方法是指该方法的实现由非Java语言实现,比如用C或C++实现。2、在定义一个native方法时,并不提供实现体(比较像定义一个Java Interface),因为其实现体是由非Java语言在外面实现的。主要是因为JAVA无法对操作系统底层进行操作,但是可以通过jni(java native interface)调用其他语言来实现底层的访问。native主要用于方法上。

Rsun2018的博客 2422

android 6.0 Java层和native守护进程socket通信

在android 系统中,有大量的地方使用socket进行通信,例如phone进程的RIL.java和rild守护进程之间的通信。 因此,本文实现一个简单的系统apk和native守护进程,实现socket通信。本篇文章基于android 6.0。 目标: 1,写一个简单的系统apk,native守护进程; 2,实现socket通信 1, 概念 Java主要代码 client = n

Jack的博客 3109

Android Java层和Native层通信实战大荟萃之LocalSocket实现通信

      Android和C/C++通过LocalSocket实现通信   前面篇章Android和C/C++通过原生socket实现通信介绍了使用原生Socket实现Android和C/C++之间的通信方式,这种方式虽然简单,但是效率并不是很高(但是也并不是一无是处,可以实现跨终端跨网络的通信)。所以Android的妈咪谷歌为我们带来了LocalSocket,比Java本身的socket效率要...

IT先森 4324

Android Java层和Native层通信实战大荟萃之JNI实现通信

        Android和C/C++通过Jni实现通信   在前面篇章Android和C/C++通过原生socket实现通信和Android和C/C++通过LocalSocket实现通信分别介绍了通过原生socket和LocalSocket实现Android和C/C++的通信方式,前面两种方式都可以实现跨进程通信,那么今天我们要介绍的就是在Android同一个进程里面通过Jni实现Java世...

IT先森 2754

android native java_在Android系统使用socket在Java层和native之间数据通信

在Android系统中,java代码和本地代码(c/c++)直接的通信一般是使用jni接口,但是这种方法一般适用于framework层调用native层的代码,但本地代码层(native)又如何把消息传递给上层呢?我们可以借鉴Android中的GSP模块的实现方式来实现native到framework的消息传递,但是比较麻烦。所以我们在这里再介绍另一种方式:socket.Android是基于lin...

weixin_29692851的博客 383

React-Native 与原生的3种交互通信(Android)

React-Native与原生(Android)的交互通信

asddavid的专栏 1万+

在Android系统使用socket在Java层和native之间数据通信

Android是基于linux的系统,系统底层机制基本上是相同的,因为分本地代码和java代码,并且是java代码通过jni调用本地代码执行。 因为UDP报文发送是有局限的,局限就是当发送方的速度远远的超过接受方的时候,底层会大量的丢失数据,而且用UDP还会比较容易引起端口的阻塞,因此需要更加强大的类来实现类似的功能。LocalServerSocket和LocalSocket正是在这样的

沧海一声笑的专栏 1726
上一篇: aosp系统源码aidl文件如何查看对应生成的java文件-安卓系统开发实战小技巧分享
下一篇: 跨进程高级玩法方案2-学员分享
千里马学框架
博客等级 码龄6年 1万+粉丝 650原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值