Android 4.4.2 Dynamic Add Jni Library method record (two app tiers)

Source: Internet
Author: User

Welcome reprint, be sure to indicate the source: http://blog.csdn.net/wang_shuai_ww/article/details/44458553

Source code: http://download.csdn.net/detail/u010406724/8515377


This article describes how to use the previously established library files.

To use the JNI library file, first we need to load it into the system. And it defines the interface to be called by the application.

Build a project, and my project name is Realarmtest. The process is omitted, and after completion, a class is created under SRC. Do not inherit other classes, the package name is Realarm.hardware, and the new class name is Hardwarecontrol. The code is as follows:

Package Realarm.hardware;public class Hardwarecontrol {public native int ledsetstate (int lednum,int ledstate); static { System.loadlibrary ("Ledjni");}}

Detailed project for example with:


The main activity file source code is as follows:

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 I    Mageview imageled;        @Override protected 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);}}); }}

is not found more concise, also easy to understand, O (∩_∩) O.

The layout file is:

<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:paddi ngbottom= "@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" > <togglebutton android:id= "@+id/btnled" Android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content" android:layout_alignleft= "@+id/imageLed" an droid:layout_alignright= "@+id/imageled" android:layout_centervertical= "true" android:textoff= "turn on the Light" and        Roid:texton= "Off light"/> <imageview android: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>
Additional resources are required. There's no way to post it. Need to go to the address provided above to download the complete project source code is available.

Finally, I would like to see the Friends of these series of articles can have a certain understanding of the Android drive to the upper application.



Android 4.4.2 Dynamic Add Jni Library method record (two app tiers)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.