Android and C.doc


文档分类:IT计算机 | 页数:约8页 举报非法文档有奖
1/8
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/8
文档列表 文档介绍
编译环境: windows7 64bit + NDK r5 + jdk6
测试环境: htc G6
因为工作需要,需要在C++代码下调用Android代码和Android代码下调用C++代码,故把实现方法记录下来。我尽量把步骤和应该注意的地方都提及,文笔不好,且代码风格皆为C++风格,请各位看官原谅。
在本文章里,需要JDK, Android NDK r5, cygwin参与编译。
简单起见,我用新的例子来说明这个过程。
主要流程的说明如下(红色函数为Android代码,蓝色函数为C++代码):
1. 点击Button,在Button响应函数里调用setName(String _strName)把EditText里的字符串传到C++代码setName()中去。
2·在C++的void setName()中,接收String,通过showNameInAndroidJNI()反向调用Android的void showNameInAndroid(String _strName),弹出对话框,显示String。
★★★★★★Android端★★★★★★★★★
以下为本程序的主界面:

////////////////////////////////////////////
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="***@string/hello"
/>
<EditText android:text=""
android:id="@+id/EditTextName"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<Button android:text="把上面的字符串发送到C++"
android:id="@+id/ButtonSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
////////////////////////////////////////////
===========Android调用C++===============
这个Android程序只有一个继承于Activity的类mainWnd:
首先要mainWnd成员里声明要在Android调用的C++函数;
public native void setName(String _strName);
native是修饰符必须的
接着在mainWnd的onCreate函数加入按钮响应
///////////按钮响应函数//////////////
Button btnSend = (Button)findViewById();
(new OnClickListener()
{

Android and C 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数8
  • 收藏数0 收藏
  • 顶次数0
  • 上传人xxj165868
  • 文件大小0 KB
  • 时间2015-10-03