Android使用使用Jni实现压力锅数据检测效果示例实现压力锅数据检测效果示例
主要介绍了Android使用Jni实现压力锅数据检测效果,涉及Android结合Jni实现进度条模拟压力锅数据监测效果的
相关操作技巧,需要的朋友可以参考下
本文实例讲述了Android使用Jni实现压力锅数据检测效果。分享给大家供大家参考,具体如下:
1、创建主页:
package com.android.imooc.jni;
import com.android.imooc.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
/**
* @描述 模仿压力锅检测数据
* @项目名称 App_imooc
* @包名 com.android.imooc.jni
* @类名 MonitorActivity
* @author chenlin
* @date 2012年6月9日 下午3:18:11
* @version 1.0
*/
public class MonitorActivity extends Activity {
static{
System.loadLibrary("monitor");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_monitor);
}
public void start(View view){
startMonitor();
}
public void stop(View view){
stopMonitor();
}
public native void startMonitor();
public native void stopMonitor();
}
2、在jni文件夹里写Monitor.c
#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include <string.h>
//获得0到100的随机数
int getPressure(){
return rand() % 101;
}
3、布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="start"
android:text="开始监测" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="stop"
android:text="结束监测" />
<com.android.imooc.jni.MyProgressBar
android:id="@+id/pb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
评论0
最新资源