OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
joth
2012/02/14 00:46:49
2012
bulach
2012/02/14 02:12:32
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
joth
2012/02/14 00:46:49
maybe comment the main purpose of this is to ensur
bulach
2012/02/14 02:12:32
Done.
| |
5 #include "base/android/jni_android.h" | |
6 #include "base/android/scoped_java_ref.h" | |
7 | |
8 using base::android::AttachCurrentThread; | |
9 using base::android::ScopedJavaLocalRef; | |
10 | |
11 class CPPClass { | |
12 public: | |
13 void Destroy(JNIEnv* env, jobject obj) { | |
14 delete this; | |
15 } | |
16 | |
17 jint Method(JNIEnv* env, jobject obj) { | |
18 return 0; | |
19 } | |
20 | |
21 ScopedJavaLocalRef<jstring> InnerMethod(JNIEnv* env, jobject obj) { | |
22 return ScopedJavaLocalRef<jstring>(); | |
23 } | |
24 }; | |
25 | |
26 namespace cpp_namespace { | |
27 | |
28 class CPPClass { | |
29 public: | |
30 jdouble MethodOtherP0(JNIEnv* env, jobject obj) { | |
31 return 0.0; | |
32 } | |
33 }; | |
34 | |
35 } // namespace cpp_namespace | |
36 | |
37 #include "jni/sample_for_tests_jni.h" | |
38 | |
39 int main() { | |
40 // On a regular application, you'd call AttachCurrentThread(). This sample is | |
41 // not yet linking with all the libraries. | |
42 JNIEnv* env = /* AttachCurrentThread() */ NULL; | |
43 // This is how you call a java static method from C++. | |
44 bool foo = Java_SampleForTests_staticJavaMethod(env); | |
45 // This is how you call a java method from C++. Note that you must have | |
46 // obtained the jobject somehow. | |
47 jobject my_java_object = NULL; | |
48 int bar = Java_SampleForTests_javaMethod(env, my_java_object, 1, 2); | |
49 return 0; | |
50 } | |
OLD | NEW |