Android HAL開発(4)
1191 ワード
http://buaadallas.blog.51cto.com/399160/371560
前の記事では、javaプログラムでC/C++を呼び出すと作成する関数を見ました.また、Androidのserviceはすでに実現しています.以下はアプリケーションがどのようにこのserviceを呼び出すかを見てみます.ここでは二つの方法を使って、簡単な第一の直接呼び出し方法を紹介します.
apps/mokoid/apps/LedCient/src/com/mokoid/LedCient/LedClient.java
前の記事では、javaプログラムでC/C++を呼び出すと作成する関数を見ました.また、Androidのserviceはすでに実現しています.以下はアプリケーションがどのようにこのserviceを呼び出すかを見てみます.ここでは二つの方法を使って、簡単な第一の直接呼び出し方法を紹介します.
apps/mokoid/apps/LedCient/src/com/mokoid/LedCient/LedClient.java
package com.mokoid.LedClient;
import com.mokoid.server.LedService;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class LedClient extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Call an API on the library.
LedService ls = new LedService();
ls.setOn(1);
ls.setOff(2);
TextView tv = new TextView(this);
tv.setText("LED 1 is on. LED 2 is off.");
setContentView(tv);
}
}
のコードは です. の で されたLedServiceを び して、このserviceのメンバー setOnとsetOffを ってハードウェアを します.
は「Mobile and Linux Deve.」のブログから ました.このソースを ず してください.http://buaadallas.blog.51cto.com/399160/371560