Developing Android apps to use hardware access services

Source: Internet
Author: User

1. Develop Android app to use hardware Access Service

~/android-2.3_r1/packages/experimental/freg

----Androidmanifest.java

----ANDROID.MK

----SRC

----Shy/luo/freg

----Freg.java

----Res

----layout

----Main.xml

----values

----String.xml

----drawable

----Icon.png


Freg.java

Package Shy.luo.freg;import Android.app.activity;import Android.os.servicemanager;import android.os.Bundle;import Android.os.ifregservice;import Android.os.remoteexception;import Android.util.log;import Android.view.View;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;public class Freg Extends Activity implements Onclicklistener {private final static String Log_tag = "shy.luo.freg.FregActivity";p rivate IF Regservice fregservice = null;private EditText valueText = null;private button Readbutton = null;private button Writebutto    n = null;private Button Clearbutton = null; /** called when the activity is first created.        */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);                Setcontentview (r.layout.main); fregservice = IFregService.Stub.asInterface (Servicemanager.getservice ("Freg"));        ValueText = (EditText) Findviewbyid (R.id.edit_value); Readbutton = (ButtoN) Findviewbyid (r.id.button_read);        Writebutton = (Button) Findviewbyid (r.id.button_write); Clearbutton = (Button) Findviewbyid (r.id.button_clear); Readbutton.setonclicklistener (this);                Writebutton.setonclicklistener (This), Clearbutton.setonclicklistener (this);    LOG.I (Log_tag, "Freg Activity Created");    } @Override public void OnClick (View v) {if (V.equals (Readbutton)) {try {int val = fregservice.getval ();    String Text = string.valueof (val); Valuetext.settext (text);}    catch (RemoteException e) {log.e (Log_tag, "Remote Exception while reading value from Freg service.");    } else if (V.equals (Writebutton)) {try {String text = Valuetext.gettext (). toString (); int val = integer.parseint (text); Fregservice.setval (val);}    catch (RemoteException e) {log.e (Log_tag, "Remote Exception while writing value to Freg service.");    } else if (V.equals (Clearbutton)) {String text = "";    Valuetext.settext (text); }    }}


Main.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/    Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " > <linearlayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:orienta tion= "vertical" android:gravity= "center" > <textview android:layout_width= "wrap_content" Android:layout_ height= "Wrap_content" android:text= "@string/value" > </TextView> <edittext android:layout_wi Dth= "Fill_parent" android:layout_height= "wrap_content" android:id= "@+id/edit_value" android:hint= "@s    Tring/hint "> </EditText> </LinearLayout> <linearlayout android:layout_width=" Fill_parent "     android:layout_height= "wrap_content" android:orientation= "horizontal" android:gravity= "center" > <Button  Android:id= "@+id/button_read"  Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "@string/read" > </B utton> <button android:id= "@+id/button_write" android:layout_width= "Wrap_content" android:layout_height    = "Wrap_content" android:text= "@string/write" > </Button> <button android:id= "@+id/button_clear" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "@string/clear" > </B Utton> </LinearLayout></LinearLayout>

Strings.xml

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <string name= "App_name" >freg</string >    <string name= "value" >Value</string>    <string name= "hint" >please input a value...</ string>    <string name= "read" >Read</string>    <string name= "Write" >Write</string>    <string name= "Clear" >Clear</string></resources>

Androidmanifest.xml

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "      package=" Shy.luo.freg "      android:versioncode=" 1 "      android:versionname=" 1.0 ">    < Application android:icon= "@drawable/icon" android:label= "@string/app_name" >        <activity android:name= ". Freg "                  android:label=" @string/app_name ">            <intent-filter>                <action android:name=" Android.intent.action.MAIN "/>                <category android:name=" Android.intent.category.LAUNCHER "/>            < /intent-filter>        </activity>    

Android.mk

Local_path:= $ (call My-dir) include $ (clear_vars) Local_module_tags: = Optionallocal_src_files: = $ (call All-subdir-java-files) Local_package_name: = Freginclude $ (build_package)

2. Compiling

Compile into apk:

The generated freg.apk is located in Out/target/product/generic/system/app.


Packaged:


Finally, the freg.apk is repackaged into the system.img, located in Out/target/product/gerneric.


Run:



The results are as follows:


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.