创建自定义Android键盘知名链接;编译,安装,但是对于这款键盘没有选择显示设备上键盘、这款、自定义、显示设备

由网友(是我闯入你的生活)分享简介:我遵循的 使用Eclipse露娜2(4.4.2)这个链接。 该应用程序编译,将APK安装在我的手机,但因为它没有活性(这是由设计)不能运行。它应该引起新的键盘选项出现在设备上的设置|语言和输入,但nooooooooooo。 我所做的只是剪切和粘贴文件名和内容,所以他们如在链路。这里的项目结构,缺乏在上面的链接的唯一项目...

我遵循的 使用Eclipse露娜2(4.4.2)这个链接。

该应用程序编译,将APK安装在我的手机,但因为它没有活性(这是由设计)不能运行。它应该引起新的键盘选项出现在设备上的设置|语言和输入,但nooooooooooo。

我所做的只是剪切和粘贴文件名和内容,所以他们如在链路。这里的项目结构,缺乏在上面的链接的唯一项目:

下面的控制台输出。所有的显然又为它应该有:

  [2015年5月9日14时58分58秒 -  SimpleKeyboard] ------------------------ ------
[2015年5月9日14时58分58秒 -  SimpleKeyboard] Android的推出!
[2015年5月9日14时58分58秒 -  SimpleKeyboard]亚洲开发银行运行正常。
[2015年5月9日14时58分58秒 -  SimpleKeyboard]没有启动的活动找到了!
[2015年5月9日14时58分58秒 -  SimpleKeyboard]的推出,将只同步设备上的应用程序包!
[2015年5月9日14时58分58秒 -  SimpleKeyboard]执行同步
[2015年5月9日14时58分58秒 -  SimpleKeyboard]自动目标模式:无法检测到设备的兼容性。请选择一个目标设备。
[2015年5月9日14点59分08秒 -  SimpleKeyboard]上传SimpleKeyboard.apk到设备TA22807EL2
[2015年5月9日14点59分08秒 -  SimpleKeyboard]安装SimpleKeyboard.apk ...
[2015年5月9日14时59分十一秒 -  SimpleKeyboard]成功!
[2015年5月9日14点59分12秒 -  SimpleKeyboard]安装在设备 SimpleKeyboard  BIN  SimpleKeyboard.apk
[2015年5月9日14点59分12秒 -  SimpleKeyboard]完成!
 

但这里的设备的屏幕,所以它并没有完全去,因为它应该有:

自定义Android键盘

如果你能发现一个明显的错误或遗漏,请让我知道。

编辑#1 的

下面是的.java项目,万一我把东西放错了地方,添加或省略了 @覆盖等无进口量的链接上显示:

 进口com.example.simplekeyboard.R;
进口android.inputmethodservice.InputMethodService;
进口android.inputmethodservice.Keyboard;
进口android.inputmethodservice.KeyboardView;
进口android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
进口android.media.AudioManager;
进口android.view.KeyEvent;
进口android.view.View;
进口android.view.inputmethod.InputConnection;

公共类SimpleIME扩展InputMethodService
    实现OnKeyboardActionListener {

    私人KeyboardView千伏;
    私人键盘键盘;
    私人布尔值上限= FALSE;

    私人无效playClick(INT键code){
      AudioManager上午=(AudioManager)getSystemService(AUDIO_SERVICE);
      开关(钥匙code){
      案例32:
          am.playSoundEffect(AudioManager.FX_KEY preSS_SPACEBAR);
          打破;
      案例Keyboard.KEY code_DONE:
      案例10:
          am.playSoundEffect(AudioManager.FX_KEY preSS_RETURN);
          打破;
      案例Keyboard.KEY code_DELETE:
          am.playSoundEffect(AudioManager.FX_KEY preSS_DELETE);
          打破;
      默认:am.playSoundEffect(AudioManager.FX_KEY preSS_STANDARD);
      }
  }

    @覆盖
    公共查看onCreateInputView(){
        KV =(KeyboardView)getLayoutInflater()膨胀(R.layout.keyboard,空)。
        键盘=新的键盘(这一点,R.xml.qwerty);
        kv.setKeyboard(键盘);
        kv.setOnKeyboardActionListener(本);
        返回千伏;
    }

    @覆盖
    公共无效onKey(int主code,INT []键codeS){
        InputConnection集成电路= getCurrentInputConnection();
        playClick(主要code);
        开关(主要code){
        案例Keyboard.KEY code_DELETE:
            ic.deleteSurroundingText(1,0);
            打破;
        案例Keyboard.KEY code_SHIFT:
            !帽=上限;
            keyboard.setShifted(帽);
            kv.invalidateAllKeys();
            打破;
        案例Keyboard.KEY code_DONE:
            ic.sendKeyEvent(新的KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEY code_ENTER));
            打破;
        默认:
            字符code =(char)的主要code;
            如果(Character.isLetter(code)及和放大器;帽){
                code = Character.toUpperCase(code);
            }
            ic.commitText(将String.valueOf(code),1);
        }
    }

    @覆盖
    在preSS(int主code){公共无效
    }

    @覆盖
    公共无效onRelease(int主code){
    }

    @覆盖
    公共无效onText(CharSequence的文字){
    }

    @覆盖
    公共无效swipeDown(){
    }

    @覆盖
    公共无效swipeLeft(){
    }

    @覆盖
    公共无效swipeRight(){
    }

    @覆盖
    公共无效swipeUp(){
    }
}
 

编辑#2 的

我刚刚发现,的Andr​​oidManifest.xml 文件夹中(下图)是不相同的的Andr​​oidManifest.xml 下的应用程序!!:

 <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.simplekeyboard
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =19/>

    <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>

        <服务机器人:名称=。SimpleIME
            机器人:标签=@字符串/ simple_ime
            机器人:权限=android.permission.BIND_INPUT_METHOD
            >
            <元数据的android:NAME =android.view.im安卓资源=@ XML /法/>
            <意向滤光器>
                <作用机器人:名称=android.view.InputMethod/>
            &所述; /意图滤光器>
        < /服务>
    < /用途>

< /舱单>
 

的Andr​​oidManifest.xml 下的应用程序:

 <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.simplekeyboard
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =19/>

    <应用
        机器人:allowBackup =真
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
    < /用途>

< /舱单>
 

编辑#3 的我改变了短清单文件是一样的长,现在我得到了简易输入法键盘为根据设置一个选项|语言和输入,但新的键盘(如下图所示),在器件上未显示:

解决方案   

我刚刚发现的Andr​​oidManifest.xml中bin文件夹(下)下的应用程序是不完全相同的Andr​​oidManifest.xml !!:

您有两个问题在这里。

首先,斌/ 输出。切勿改装的东西,在斌/ 。因此,<服务> 您将在清单中需要走在了的Andr​​oidManifest.xml 文件,该文件是在你的项目的根。

二,假设你刚刚动了<服务> 元素切换到适当的清单,Java类必须是 com.example .simplekeyboard.SimpleIME 。现在,你有 SimpleIME 在默认包在Java中,这是即使在正常的Java开发很少适当的,更不用说在Android系统。

因此​​,移动<服务> 元素(和之前所做的任何其他更改)的权利清单,并移动 SimpleIME 到正确的软件包。

I followed the instructions in this link using Eclipse Luna 2 (4.4.2).

The app compiled, and the apk was installed on my phone, but since it has no activity (which is by design) it can't be run. It's supposed to cause a new keyboard option to appear in the device's Settings | Language and Input, but nooooooooooo.

All I did was cut and paste file names and contents, so they're as shown at the link. Here's the project structure, the only item lacking in the link above:

Here's console output. All apparently went as it should have:

[2015-05-09 14:58:58 - SimpleKeyboard] ------------------------------
[2015-05-09 14:58:58 - SimpleKeyboard] Android Launch!
[2015-05-09 14:58:58 - SimpleKeyboard] adb is running normally.
[2015-05-09 14:58:58 - SimpleKeyboard] No Launcher activity found!
[2015-05-09 14:58:58 - SimpleKeyboard] The launch will only sync the application package on the device!
[2015-05-09 14:58:58 - SimpleKeyboard] Performing sync
[2015-05-09 14:58:58 - SimpleKeyboard] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2015-05-09 14:59:08 - SimpleKeyboard] Uploading SimpleKeyboard.apk onto device 'TA22807EL2'
[2015-05-09 14:59:08 - SimpleKeyboard] Installing SimpleKeyboard.apk...
[2015-05-09 14:59:11 - SimpleKeyboard] Success!
[2015-05-09 14:59:12 - SimpleKeyboard] SimpleKeyboardbinSimpleKeyboard.apk installed on device
[2015-05-09 14:59:12 - SimpleKeyboard] Done!

But here's device screen, so it didn't QUITE go as it should have:

If you can spot an obvious error or omission, PLEASE let me know.

EDIT #1

Here's the .java for the project, in case I put something in wrong place, added or omitted an @Override etc. No imports were shown on the link:

import com.example.simplekeyboard.R;
import android.inputmethodservice.InputMethodService;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
import android.media.AudioManager;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputConnection;

public class SimpleIME extends InputMethodService
    implements OnKeyboardActionListener{

    private KeyboardView kv;
    private Keyboard keyboard;
    private boolean caps = false;

    private void playClick(int keyCode){
      AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
      switch(keyCode){
      case 32: 
          am.playSoundEffect(AudioManager.FX_KEYPRESS_SPACEBAR);
          break;
      case Keyboard.KEYCODE_DONE:
      case 10: 
          am.playSoundEffect(AudioManager.FX_KEYPRESS_RETURN);
          break;
      case Keyboard.KEYCODE_DELETE:
          am.playSoundEffect(AudioManager.FX_KEYPRESS_DELETE);
          break;              
      default: am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD);
      }       
  }

    @Override
    public View onCreateInputView() {
        kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
        keyboard = new Keyboard(this, R.xml.qwerty);
        kv.setKeyboard(keyboard);
        kv.setOnKeyboardActionListener(this);
        return kv;
    }

    @Override
    public void onKey(int primaryCode, int[] keyCodes) {        
        InputConnection ic = getCurrentInputConnection();
        playClick(primaryCode);
        switch(primaryCode){
        case Keyboard.KEYCODE_DELETE :
            ic.deleteSurroundingText(1, 0);
            break;
        case Keyboard.KEYCODE_SHIFT:
            caps = !caps;
            keyboard.setShifted(caps);
            kv.invalidateAllKeys();
            break;
        case Keyboard.KEYCODE_DONE:
            ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
            break;
        default:
            char code = (char)primaryCode;
            if(Character.isLetter(code) && caps){
                code = Character.toUpperCase(code);
            }
            ic.commitText(String.valueOf(code),1);                  
        }
    } 

    @Override
    public void onPress(int primaryCode) {
    }

    @Override
    public void onRelease(int primaryCode) {            
    }

    @Override
    public void onText(CharSequence text) {     
    }

    @Override
    public void swipeDown() {   
    }

    @Override
    public void swipeLeft() {
    }

    @Override
    public void swipeRight() {
    }

    @Override
    public void swipeUp() {
    }
}

EDIT #2

I just discovered that AndroidManifest.xml in bin folder (below) is NOT identical to AndroidManifest.xml under app!!:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simplekeyboard"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <service android:name=".SimpleIME"
            android:label="@string/simple_ime"
            android:permission="android.permission.BIND_INPUT_METHOD"
            >
            <meta-data android:name="android.view.im" android:resource="@xml/method"/>
            <intent-filter>
                <action android:name="android.view.InputMethod" />
            </intent-filter>            
        </service>        
    </application>

</manifest>

AndroidManifest.xml under app:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.simplekeyboard"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    </application>

</manifest>

EDIT #3 I changed the "short" manifest file to be same as "long" and now I DO GET the Simple IME keyboard as an option under Settings | Language and Input but the new keyboard (shown below) is NOT shown on device:

解决方案

I just discovered that AndroidManifest.xml in bin folder (below) is NOT identical to AndroidManifest.xml under app!!:

You have two problems here.

First, bin/ is output. Never modify stuff in bin/. So the <service> that you put in the manifest needs to go in the AndroidManifest.xml file that is in your project root.

Second, assuming that you just move that <service> element over to the proper manifest, the Java class needs to be com.example.simplekeyboard.SimpleIME. Right now, you have SimpleIME in the default package in Java, which is rarely appropriate even in normal Java development, let alone in Android.

So, move the <service> element (and any other changes that you made) to the right manifest, and move SimpleIME to the right package.

阅读全文

相关推荐

最新文章