Native android softkeyboard on NDK

2,403 views
Skip to first unread message

Maidul Islam

unread,
Jul 30, 2012, 12:34:13 AM7/30/12
to android-ndk
I have an android NDK application.In this application coding in c++
language.There some resource file .C++ aceess this file and show in
Mobile.Now I want to open android soft keyboard and write
something.How I open Native android on NDK Application.
...................
OR
How can I open Native android soft keyboard on NDK apps.

...........
If anyone have idea then please help me.

Ian Ni-Lewis

unread,
Jul 30, 2012, 3:36:00 PM7/30/12
to andro...@googlegroups.com
The NDK isn't intended to provide access to the Android GUI framework. Use the standard Java framework for that.
Ian



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
Ian Ni-Lewis
Developer Advocate
Android Developer Relations


Doug Linder

unread,
Jul 31, 2012, 1:48:42 AM7/31/12
to andro...@googlegroups.com
There was some talk about this on the moai dev list a while back that might be relevant to your interests.

Moai is a _lua_ based scripting application game-framwork thingo, but it's C++ under the hood, and you could easily build some C++ / lua bridging to use their libraries; they definitely have a gui layer that works pretty well completely independently of the android ui, and there's an ios software keyboard... you'll have to search the forum to see what the state-of-play is for an android touch keyboard is though~

~
Doug.

Doug Linder

unread,
Jul 31, 2012, 9:03:15 PM7/31/12
to andro...@googlegroups.com
Oh, that's a clever trick. Thanks for sharing that. 

On Wednesday, August 1, 2012 3:56:25 AM UTC+8, step_jac wrote:
Hi Maidul,

You can achieve this from your C++ code by using JNI to talk back to the Java app framework.
In our case, we subclass NativeActivity and invoke it as follows:

Java Code:

package com.yourcompany.yourapp;
...
class Keyboard
{
    static void Show()
    {
        InputMethodManager m = (InputMethodManager)NativeActivitySubclass.Get().getSystemService(Context.INPUT_METHOD_SERVICE);
        m.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
   
    static void Hide()
    {
        InputMethodManager m = (InputMethodManager)NativeActivitySubclass.Get().getSystemService(Context.INPUT_METHOD_SERVICE);
        m.toggleSoftInput(0, 0);       
    }
}

C++ Code:
        JNIEnv* env = System::GetJNI(); //gets a JNI for this thread

        jclass keyboard = Util::Java::LoadClass( "com.yourcompany.yourapp.Keyboard"); //uses class loader internally since this thread does not have direct access to this user defined class
        jmethodID show = env->GetStaticMethodID( keyboard, "Hide", "()V");
        env->CallStaticVoidMethod( keyboard, show );

Best,

Stephane Jacoby

step_jac

unread,
Aug 1, 2012, 3:10:02 PM8/1/12
to andro...@googlegroups.com
Hi Maidul,

You will need to provide your own implementation of LoadClass and GetJNI.
This link should provide the details needed; http://blog.tewdew.com/post/6852907694/using-jni-from-a-native-activity

Best,

Stephane

On Tuesday, 31 July 2012 23:30:09 UTC-7, Maidul Islam wrote:

Hello step_jac,
I am new on JNI and NDK.
according to your code, when I am running I got compilation error.

Could you please send me a whole source  code to my email mmaidu...@gmail.com

Best Regards,
Maidul

On Wednesda August 1, 2012 9:19:00 AM UTC+5:30, Maidul Islam wrote:
Hello Stephane Jacoby,
Thank you very much for your help.
Best Regards,
Maidul
Reply all
Reply to author
Forward
0 new messages