大家好我正在写一个处理我的设备的LED的服务。 我喜欢写/ sys文件系统,但似乎没有工作.... 看起来是因某种原因失败,可能是权限? 接收器工作,但无法写入/ sys ...
我的接收者:
package com.gabrielgagz.ledpearlyn;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import java.io.*;
public class LedPearlynReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(final Context context, final Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, LedPearlynService.class);
context.startService(serviceIntent);
Log.i("LedPearlyn","Started");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF) || intent.getAction().equals(Intent.ACTION_DREAMING_STARTED)) {
try {
String[] cmd = { "sh", "-c", "echo 0 > /sys/class/leds/pearlyn/brightness"};
Runtime.getRuntime().exec(cmd);
} catch(IOException ie) {
ie.printStackTrace();
}
wasScreenOn = false;
Log.i("LedPearlyn","Off");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON) || intent.getAction().equals(Intent.ACTION_DREAMING_STOPPED)) {
try {
String[] cmd = { "sh", "-c", "echo 255 > /sys/class/leds/pearlyn/brightness"};
Runtime.getRuntime().exec(cmd);
} catch(IOException ie) {
ie.printStackTrace();
}
wasScreenOn = true;
Log.i("LedPearlyn","On");
}
}
}