我尝试在单击按钮后从应用程序启动输入法设置,但它不起作用 我试图添加权限但不起作用
btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent in=new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
startActivityForResult(in);
}
private void startActivityForResult(Intent intent) {
}
});
这就是清单:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.setting.INPUT_METHOD_SETTINGS"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="Myapp"
android:label="@string/app"
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>
答案 0 :(得分:0)
首先,您应该拨打另一个startActiivtyForResult。 然后,在“您的活动”中,您应该覆盖不同的onActivityResult方法。希望这些链接可以帮助你。
修改
是的,确实有效。看一个非常快速的样本:
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
private static final int INPUT_METHOD_RESULT = 947;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent in = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
startActivityForResult(in, INPUT_METHOD_RESULT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(MainActivity.class.getSimpleName(), "Returning from input settings with code: " + requestCode);
}
}