How Android Development calls so

Source: Internet
Author: User

Java

 PackageCom.example.callsodemo;ImportAndroid. R.integer;ImportAndroid. r.string;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem; Public classMainactivityextendsactionbaractivity { Public native intADD (intXinty);  Public native voidwritelog (String str); Static {        //loading the dynamic librarySystem.loadlibrary ("Zhentry"); } @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); inti = ADD (5, 8); Writelog ("14521452"); intj =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) {    returnx+y;} JniexportvoidJnicall 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); intD=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);}

Attention:

1 Naming of functions in C

2 c requires transformation when using Java parameters, such as char *str = (*env)->getstringutfchars (env, prompt, 0);

How Android Development calls so

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.