开发Android应用程序来使用硬件访问服务
2014-06-08 20:44
351 查看
1、开发Android应用程序来使用硬件访问服务
~/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
main.xml
strings.xml
AndroidManifest.xml
Android.mk
2、编译
编译成apk:
生成的Freg.apk位于out/target/product/generic/system/app中。
打包:
最后把Freg.apk重新打包进入system.img,位于out/target/product/gerneric中。
运行:
结果如下:
~/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
<?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:orientation="vertical" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/value"> </TextView> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/edit_value" android:hint="@string/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"> </Button> <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"> </Button> </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> </application> </manifest>
Android.mk
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := Freg include $(BUILD_PACKAGE)
2、编译
编译成apk:
生成的Freg.apk位于out/target/product/generic/system/app中。
打包:
最后把Freg.apk重新打包进入system.img,位于out/target/product/gerneric中。
运行:
结果如下:
相关文章推荐
- Android 6.0中应用程序使用硬件访问服务实例
- 硬件访问服务2之让Android应用程序访问C库
- 编写Android应用程序验证硬件访问服务
- 开发Android硬件访问服务
- tiny210 hal 6 Android系统中编写APP通过应用程序框架层访问硬件服务。
- Android驱动(一)硬件访问服务学习之(四)Android应用程序APP编写
- 5.Android硬件访问服务使用反射
- Android 系统源码情景分析读书笔记(1)----开发Android 硬件访问服务
- HAL(4) -- 开发android源码硬件访问服务和应用测试程序
- 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务 和 在Ubuntu上为Android系统内置Java应用程序测试Application Frame
- 开发Android硬件访问服务
- 在Android上使用AutoNavi Map API开发自己的地图应用程序
- 使用PHP 开发基于Web 服务的应用程序
- 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务
- 在Ubuntu为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口
- 在Ubuntu上为Android系统内置Java应用程序测试Application Frameworks层的硬件服务
- 在Ubuntu上为Android系统内置Java应用程序测试Application Frameworks层的硬件服务
- 在Ubuntu上为Android系统的Application Frameworks层增加硬件访问服务
- Android访问WCF服务(上篇)-服务端开发
- 使用Python开发Android应用程序:第三节 在电脑上编写程序在手机上运行