Develop Android applications to use hardware to access services

Source: Internet
Author: User

1. Develop Android applications to use hardware to access services

~ /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";private IFregService fregService = null;private EditText valueText = null;private Button readButton = null;private Button writeButton = 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

 
     
      
       
       
       
       
       
      
           
           
           
  
 

Strings. xml

 
     
  
   Freg
      
  
   Value
      
  
   Please input a value...
      
  
   Read
      
  
   Write
      
  
   Clear
  
 

AndroidManifest. xml

 
                         
                                  
               
              
  

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. Compile

Compile to apk:

The generated freg.apk is located in out/target/product/generic/system/app. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PGJyPgo8L3A + cjxwpiagicagiltyspyjuw.vcd4kpha + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140609/201406090910363.png" alt = "\">

Repackage freg.apk to system. img, which is located in out/target/product/gerneric.


Run:



The result is as follows:


Related Article

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.