APP端:
打开eclipse,file-new-android application project之后输入app的名字即可。
在androidmanifest。xml里增加shred userid =android.uid.system。
将一个按键直接拖进app界面:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="42dp"
android:layout_marginTop="129dp"
android:onClick="sendMessage"
android:text="Button" />
然后修改。java文件
package com.example.matt;
import android.support.v7.app.ActionBarActivity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.os.SystemProperties;
public class MainActivity extends ActionBarActivity {
private SensorManager sensorMgr;
private SensorEventListener lsn1;
private float x, y, z;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
lsn1= new SensorEventListener(){//实现接口
public void onSensorChanged(SensorEvent e) {//重写方法
x = e.values[0];
y = e.values[1];
z = e.values[2];
TextView textview =(TextView) findViewById(R.id.textView1);
textview.setText("Gsensor: "+x+" , "+y+" , "+z);
}
public void onAccuracyChanged(Sensor s, int accuracy) {
}
};
Sensor sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorMgr .registerListener(lsn1, sensor, SensorManager.SENSOR_DELAY_UI);
}
public void sendMessage(View view) {
// Do something in response to button
int rotation = SystemProperties.getInt("debug.sensor.rotation", 0);
if(rotation==0){//true
SystemProperties.set("debug.sensor.rotation","1");
}else{//false
SystemProperties.set("debug.sensor.rotation","0");
}
}
@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;
}
protected void onPause() {
super.onPause();
sensorMgr.unregisterListener(lsn1);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
最后再点击自己工程的属性properties,然后在java build path中点击libraries-add external jars然后选择sdk文件中的layoutlib.jar。
然后点击run按键,出现什么添加虚拟机的都点no 或者cancel。最后到workspace的该工程生成的apk文件所在的文件夹下,将
out/host/linux-x86/framework/signapk.jar
vendor/intel/PRIVATE/cert/platform.pk8
vendor/intel/PRIVATE/cert/platform.x509.pem
这三个文件烤进去之后,在当前文件夹的terminal里运行
java -jar signapk.jar platform.x509.pem platform.pk8 matt.apk matt1.apk
matt是原来工程名,matt1是希望签名之后的工程名。
到此app段结束
源码段:
long int start_time=0;
long int end_time=0;
int j=0;
先在acckxtj2.cpp文件中添加这几个全局变量
int Kxtj2::readEvents(sensors_event_t* data, int count)在这个函数中
char value[PROPERTY_VALUE_MAX];//add
int property;
property_get("debug.sensor.rotation",value,"0");
property=atoi(value);
while (count && mInputReader.readEvent(&event)) {
int type = event->type;
if (type == EV_ABS) {
float value = event->value;
if(property==0)
{
if (event->code == EVENT_TYPE_ACCEL_X) {
mPendingEvent.acceleration.x = KIONIX_UNIT_CONVERSION(value);
} else if (event->code == EVENT_TYPE_ACCEL_Y) {
mPendingEvent.acceleration.y = KIONIX_UNIT_CONVERSION(value);
} else if (event->code == EVENT_TYPE_ACCEL_Z) {
mPendingEvent.acceleration.z = KIONIX_UNIT_CONVERSION(value);
}
start_time=0;
}
else
{
time(&end_time);
if((end_time-start_time)>=10){
if(j==0){
mPendingEvent.acceleration.x = 10;
mPendingEvent.acceleration.y = 0;
mPendingEvent.acceleration.z = 0;
time(&start_time);
}else if(j==1){
mPendingEvent.acceleration.x = 0;
mPendingEvent.acceleration.y = -10;
mPendingEvent.acceleration.z = 0;
time(&start_time);
}else if(j==2){
mPendingEvent.acceleration.x = -10;
mPendingEvent.acceleration.y = 0;
mPendingEvent.acceleration.z = 0;
time(&start_time);
}else if(j==3){
mPendingEvent.acceleration.x = 0;
mPendingEvent.acceleration.y = 10;
mPendingEvent.acceleration.z = 0;
time(&start_time);
j=-1;
}
j++;
}
}
} else if (type == EV_SYN) {
mPendingEvent.timestamp = timevalToNano(event->time);
if (mEnabled) {
*data++ = mPendingEvent;
count--;
numEventReceived++;
}
} else {
ALOGE("kxtj2.cpp: unknown event (type=%d, code=%d)",
type, event->code);
}
mInputReader.next();
}
return numEventReceived;
}
然后局部编译:
source build/envsetup.sh
lunch(选择k013 eng)也就是25
25
cd hardware/akm/akm09911
mm ./
就编译出来一个so文件
接着是将so文件和apk文件放入pad
adb remount
adb push sensors.K013.so /system/lib/hw
adb reboot
adb shell
adb install matt1.apk
adb uninstall matt.apk
然后就搞定了