zoukankan      html  css  js  c++  java
  • TQ210搭载Android4.0.3系统构建之BEEP从驱动到HAL到JNI到应用程序(上层应用篇)

      其实上层应用篇 很简单

      对于BeepActivity.java 可能需要注意一下的就是 包名、类名、方法名的编写一定要与JNI层定义的方法名要一致 不然会提示找不到JNI层的方法的

      比如 包名com.under.beep  类名BeepActivity  方法名beepOn

      BeepActivity.java

    package com.under.beep;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.view.Menu;
    import android.view.View;
    import android.widget.CheckBox;
    
    public class BeepActivity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_beep);
    		if(!beepInit())  //蜂鸣器初始化函数
    		{
    			new AlertDialog.Builder(BeepActivity.this).setTitle("error").setMessage("failed to init beep.").setPositiveButton("确定", null).show();
    		}
    	}
    
    	
    	public void checkOnOff(View view)
    	{
    		switch (view.getId()) {
    		case R.id.checkBox1: //蜂鸣器的单击事件
    			CheckBox checkBox=(CheckBox)view;
    			if(checkBox.isChecked()) beepOn(1);
    			else beepOff(0);
    			break;
    		case R.id.button1:  //退出系统
    			this.finish();
    			break;
    		}
    		
    		
    	}
    	
    	//本地函数
    	public native boolean beepOn(int cmd);
    	public native boolean beepOff(int cmd);
    	public native boolean beepInit();
    	public native boolean beepClose();
    	
    	//加载动态共享库
    	static{
    		System.loadLibrary("beepunder");
    	}
    	
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.beep, menu);
    		return true;
    	}
    
    }
    


    布局文件

    activity_beep.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".BeepActivity" >
    
        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="checkOnOff"
            android:text="打开蜂鸣器" />
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="checkOnOff"
            android:text="退出" />
    
    </LinearLayout>
    


  • 相关阅读:
    We need know.
    vue2.x加入fullpage全屏插件
    解决浏览器url带值访问报错URL编码encodeURI
    vue子组件修改父组件的值(子传父 )
    cli3多页面 webpack打包日志记录
    解决vue-cli npm run build之后vendor.js文件过大的方案
    vue使用UEditor富文本编辑器[实用]
    解决 cli3 自定义指令在ie11报错 SCRIPT1002: 语法错误
    cli3搭建项目配置代理跨域
    简易日期联动选择代码demo
  • 原文地址:https://www.cnblogs.com/liangxinzhi/p/4275625.html
Copyright © 2011-2022 走看看