日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

Android 4.4.2 动态添加JNI库方法记录 (二 app应用层)

發(fā)布時(shí)間:2024/9/3 Android 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 4.4.2 动态添加JNI库方法记录 (二 app应用层) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

歡迎轉(zhuǎn)載,務(wù)必注明出處:http://blog.csdn.net/wang_shuai_ww/article/details/44458553

源碼下載地址:http://download.csdn.net/detail/u010406724/8515377


本篇介紹怎么使用前面建立好的庫(kù)文件。

要使用JNI庫(kù)文件,那么首先我們是需要把它加載到系統(tǒng)中,并對(duì)其定義接口,供給應(yīng)用來(lái)調(diào)用。

建立一個(gè)工程,我的工程名為RealArmTest,過程就省略了,完成后再在src下建立一個(gè)類,不繼承其他類,包名為realarm.hardware,新建的類名為HardwareControl。代碼如下:

package realarm.hardware;public class HardwareControl {public native int LedSetState(int ledNum,int ledState);static {System.loadLibrary("LedJni");}}
具體的工程如下圖:


主activity文件源碼如下:

package com.example.realarmtest;import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.ToggleButton; import realarm.hardware.HardwareControl;;public class MainActivity extends Activity {private HardwareControl MyLedTest = null;private ToggleButton btnLed;private ImageView imageLed;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btnLed = (ToggleButton) findViewById(R.id.btnLed);imageLed = (ImageView) findViewById(R.id.imageLed);MyLedTest = new HardwareControl();MyLedTest.LedSetState(0, 0);imageLed.setImageResource(R.drawable.bulboff);btnLed.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if(btnLed.isChecked()){imageLed.setImageResource(R.drawable.bulbon);MyLedTest.LedSetState(0, 1);}else {imageLed.setImageResource(R.drawable.bulboff);MyLedTest.LedSetState(0, 0);}}});} }
是不是發(fā)現(xiàn)更簡(jiǎn)潔了,也容易理解,O(∩_∩)O。

布局文件為:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.example.ledtest.MainActivity" ><ToggleButtonandroid:id="@+id/btnLed"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/imageLed"android:layout_alignRight="@+id/imageLed"android:layout_centerVertical="true"android:textOff="開燈"android:textOn="關(guān)燈" /><ImageViewandroid:id="@+id/imageLed"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@+id/btnLed"android:layout_centerHorizontal="true"android:layout_marginBottom="22dp"android:src="@drawable/bulboff" /></RelativeLayout> 另外還需要資源圖片,這里就沒法貼出來(lái)了,需要的去上面提供的地址下載完整工程源碼就有了。

最后愿看這些系列文章的朋友都能對(duì)Android驅(qū)動(dòng)到上層應(yīng)用有一定的了解。



總結(jié)

以上是生活随笔為你收集整理的Android 4.4.2 动态添加JNI库方法记录 (二 app应用层)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。