在A20上示範老羅的Android硬體抽象層(HAL)概要介紹和學習計劃5–關於APP部分

來源:互聯網
上載者:User

在/packages/apps/下建立myapp,用eclipse建立個工程,這樣利用ADT產生設定檔快點,複製到/packages/apps/myapp/把gen/com/example/myapp/R.java定義的類刪掉,別重複了。

主要代碼如下:

/packages/apps/myapp/src/com/example/myapp/MainActivity.java:

package com.example.myapp;

import com.example.myapp.R;
import android.app.Activity;
import android.os.ServiceManager;  
import android.os.Bundle;
import android.os.IHelloService;  
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 MainActivity extends Activity implements OnClickListener {

   private final static String LOG_TAG = "com.example.myapp.Hello";  
     
   private IHelloService helloService = null;  
 
   private EditText valueText = null;  
   private Button readButton = null;  
   private Button writeButton = null;  
   private Button clearButton = null;  

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        helloService = IHelloService.Stub.asInterface(ServiceManager.getService("hello"));  

        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, "Hello Activity Created");  
    }  

    
    @Override  
    public void onClick(View v) {  
        if(v.equals(readButton)) {  
        try {  
                int val = helloService.getVal();  
                String text = String.valueOf(val);  
                valueText.setText(text);  
        } catch (RemoteException e) {  
            Log.e(LOG_TAG, "Remote Exception while reading value from device.");  
        }         
        }  
        else if(v.equals(writeButton)) {  
        try {  
                String text = valueText.getText().toString();  
                int val = Integer.parseInt(text);  
            helloService.setVal(val);  
        } catch (RemoteException e) {  
            Log.e(LOG_TAG, "Remote Exception while writing value to device.");  
        }  
        }  
        else if(v.equals(clearButton)) {  
            String text = "";  
            valueText.setText(text);  
        }  
    }  

    //@Override
    //public boolean onCreateOptionsMenu(Menu menu) {
    //    // Inflate the menu; this adds items to the action bar if it is present.
    //    getMenuInflater().inflate(R.menu.main, menu);
    //    return true;
    //}
    
}

然後是/packages/apps/myapp的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 := myapp 
include $(BUILD_PACKAGE)

LOCAL_PACKAGE_NAME := myapp 的myapp要不寫在build裡的*.mk或者去

/device/softwinner/wing-XXX/wing_XXX.mk添加:

PRODUCT_PACKAGES += \
    myapp

以上方法由大家喜歡了,只要達到目的就可以。最後make下就可以了:

主要編譯出來的或者關聯的東西有:

/system/lib/libsystem_server.so

/system/lib/hw/hello.default.so

/system/app/myapp.apk

     

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.