码迷,mamicode.com
首页 > 移动开发 > 详细

android开发 如何调用SO

时间:2015-09-09 09:45:36      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

java

package com.example.callsodemo;

import android.R.integer;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {
    public native int Add(int x, int y);
    
    public native void WriteLog(String str);

    static {
        // 加载动态库
        System.loadLibrary("zhentry");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        int i = Add(5, 8);
        WriteLog("14521452");
        int j = i;
    }

c

#include <stdio.h>
#include <time.h>
#include <pthread.h>
#include <jni.h>

JNIEXPORT jint JNICALL Java_com_example_callsodemo_MainActivity_Add(JNIEnv *env, jobject obj,
        jint x, jint y) {

    return x+y;
}
JNIEXPORT void JNICALL Java_com_example_callsodemo_MainActivity_WriteLog(JNIEnv *env, jobject obj, jstring prompt) {

    //int d = system("touch /sdcard/zhang.txt");
    //int d = system("/data/local/tmp/screencap -p /sdcard/zzz.png");
    char *args[] = {"sh","-c","/data/local/tmp/screencap -p /sdcard/zzz.png",NULL};
    execv("/system/bin/sh",args);
    int d=223;
    //int e = seteuid(2000);
    //int d = getuid();
    char *str = (*env)->GetStringUTFChars(env, prompt, 0);
    FILE *stream;
    stream = fopen("/sdcard/zhentry.log", "a+,ccs=utf-8");
    fprintf(stream, "%s|%d\n", str,d);
    fclose(stream);
}

注意:

1 C中函数的命名

2 C中使用JAVA参数时需要转型,如char *str = (*env)->GetStringUTFChars(env, prompt, 0);

android开发 如何调用SO

标签:

原文地址:http://www.cnblogs.com/bloodofhero/p/4793621.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!