zoukankan      html  css  js  c++  java
  • android开发 如何调用SO

    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
    ", str,d);
        fclose(stream);
    }

    注意:

    1 C中函数的命名

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

  • 相关阅读:
    java实现可安装的exe程序
    WINDOWS上使用BAT定期执行备份操作
    Freemaker基于word模板动态导出
    网页静态化Freemarker
    Linux下Mysql每天自动备份
    搭建cas单点登录服务器
    GridView多列排序
    python学习-发送邮件(smtp)
    python3+selenium3学习——发送邮件
    redis相关-基础语法
  • 原文地址:https://www.cnblogs.com/bloodofhero/p/4793621.html
Copyright © 2011-2022 走看看