Как запустить InputMethodService с помощью Broadcastreceiver или Intent в Android? - PullRequest
2 голосов
/ 29 сентября 2011

У нас есть InputMethodService как отдельное приложение, теперь мы хотим запустить этот InputMethodService для определенного действия в другом приложении.Мы попытались использовать широковещательный приемник, но он выдает следующую ошибку:

Intent myService = new Intent(context, Cs_key.class);
context.startService(myService);

LOGCATE:

-

29 11:06:51.624: ERROR/AndroidRuntime(24087): FATAL EXCEPTION: main
09-29> 09 11:06:51.624: ERROR/AndroidRuntime(24087): java.lang.RuntimeException: Unable to start receiver com.ashwin.demo.keyboard.KeyboardReceiver: java.lang.SecurityException: Not allowed to start service Intent { cmp=com.ashwin.demo.keyboard/.Cs_key } without permission android.permission.BIND_INPUT_METHOD
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.app.ActivityThread.access$3200(ActivityThread.java:125)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.os.Looper.loop(Looper.java:123)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at java.lang.reflect.Method.invokeNative(Native Method)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at java.lang.reflect.Method.invoke(Method.java:521)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at dalvik.system.NativeStart.main(Native Method)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): Caused by: java.lang.SecurityException: Not allowed to start service Intent { cmp=com.ashwin.demo.keyboard/.Cs_key } without permission android.permission.BIND_INPUT_METHOD
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.app.ContextImpl.startService(ContextImpl.java:832)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.content.ContextWrapper.startService(ContextWrapper.java:336)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.content.ContextWrapper.startService(ContextWrapper.java:336)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at com.ashwin.demo.keyboard.KeyboardReceiver.onReceive(KeyboardReceiver.java:18)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)

menifestfile

  <?xml version="1.0" encoding="utf-8"?>
   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      android:versionCode="1"
      android:versionName="1.0" package="com.ashwin.demo.keyboard">
    <uses-permission android:name="android.permission.BIND_INPUT_METHOD"/>
    <application android:label="@string/app_name" >
        <service android:name="Cs_key" android:exported="true"
                android:permission="android.permission.BIND_INPUT_METHOD">
            <intent-filter>
                <action android:name="android.view.InputMethod" />
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
            <meta-data android:name="android.view.im" android:resource="@xml/method" />
        </service>
    <receiver android:name=".KeyboardReceiver"
    android:permission="android.permission.BIND_INPUT_METHOD">
    <intent-filter>
         <action  android:name="android.intent.action.TIME_SET"></action>
            </intent-filter>
    </receiver>
    </application>

     </manifest>
...