Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <jni.h>
- #include <string>
- #include <time.h>
- extern "C" JNIEXPORT jstring JNICALL
- Java_com_example_phi_myapplication6_MainActivity_stringFromJNI(
- JNIEnv *env,
- jobject /* this */) {
- std::string hello = "Hello from C++";
- return env->NewStringUTF(hello.c_str());
- }
- extern "C" JNIEXPORT jstring JNICALL
- Java_com_example_phi_myapplication6_MainActivity_getStringRandom(
- JNIEnv *env,
- jobject /* this */) {
- size_t length =10;
- auto randchar = []() -> char
- {
- const char charset[] =
- "0123456789"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz";
- const size_t max_index = (sizeof(charset) - 1);
- return charset[ rand() % max_index ];
- };
- std::string randomstr(length,0);
- std::generate_n( randomstr.begin(), length, randchar );
- return env->NewStringUTF(randomstr.c_str());
- }
Add Comment
Please, Sign In to add comment