문제

I need the sample code for how to edit the System Using Jni. i need to edit the file in the location /sys/class/gpio/gpio41/value

I tried These codes But It Is Not Working.

#include <jni.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>



 jstring
       Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                              jobject thiz )
 {

int fd ;
    char gpio_path[30];
    sprintf(gpio_path,"/sys/class/gpio/gpio41/value");



    fd = open(gpio_path, O_RDWR | O_NONBLOCK );

        write(fd, "1", 2);


    close(fd);



return (*env)->NewStringUTF(env, gpio_path);

}

도움이 되었습니까?

해결책 2

Giving Permission to File Executing the command

chmod 777 /sys/class/gpio/gpio41/value

It Worked................

다른 팁

In general, sysfs files are not writable in android for security issue.

Specific applications can be writable have suitable uid such as system, media, graphics, etc.

See https://android.googlesource.com/platform/cts/+/master/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java and look testAllFilesInSysAreNotWritable() method.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top