1

Hi I am working on soft keyboard.

I am getting exception of permission when I am accessing my service class from my simple activity class.

Stack Trace of exception is shown below,

enter image description here

In above image InputServiceMethod class = Underlined by Green color.

Activity class = Underlined by Blue color.

I am getting this exception when I am calling InputServiceMethod class from activity class.

For this I used the below code which gives me exception,

Intent intent = new Intent(v.getContext(),SoftKeyboard.class); startService(intent); finish(); 

My manifest file as shown below,

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.softkeyboard" android:installLocation="preferExternal"> <uses-permission android:name="android.permission.VIBRATE" /> <!-- <permission android:name="android.permission.BIND_INPUT_SERVICE" --> <!-- android:exported="true"></permission> --> <application android:label="@string/ime_name"> <service android:name="com.example.android.softkeyboard.SoftKeyboard" android:permission="android.permission.BIND_INPUT_METHOD" android:exported="true"> <intent-filter> <action android:name="android.view.InputMethod" /> </intent-filter> <meta-data android:name="android.view.im" android:resource="@xml/method" /> </service> <activity android:name="com.configuration.Configuration" android:label="@string/title_activity_configuration" > </activity> </application> 

I don't understand as even if I give permission about BIND_INPUT_METHOD it is throwing exception.

How to fix it? Thanks

2 Answers 2

2

It looks like you are binding service to action android.view.InputMethod while it is protected by permission android.permission.BIND_INPUT_METHOD which is used to ensure that only the system can bind to it by its protection level. So According to Android you can only define the keyboard handling service but can't call it explicitly, it will be called automatically by system whenever a input method is required. So there are two ways to solve it: 1. Let it be called by system, don't call it explicit, or 2. Sign your application with system's signature you are running on, which makes your application platform dependent. (Not advised if your building generic application).

Hope you understand the situation.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for reply. But the problem is it is giving me exception when I try to use this app on older version now I am testing it on gingerbread 2.3.6. But it is fine working on any jelly bean device version 4+.
I don't think that is working fine as on android 4+ they just ignore the permissoin, but may be thrown in older version. By seeing the android's internal code (InputMethodManagerService) you can look that in 4+ they are ignoring without permission services.
Thanks Neeraj Nama it done the trick, as you said I used option 1, and in code I just used finish(); which worked just like device back button. As if I doesn't need to use this function, but to add just usablity of app I have to use back button explicitly.
0

The permission you are using i.e: permission about BIND_INPUT_METHOD
is only for system apps and mostly will work only on rooted devices, it wont accept on unrooted devices.

1 Comment

Wrong answer bro. See my answer. It has nothing to do with rooted device.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.