package cn.testsimeji; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.app.Activity; import android.content.Intent; /** * Demo描述: * simeji使用示例 * * 註意事項: * 1 在配置文件中添加 * <action android:name="com.adamrocker.android.simeji.ACTION_INTERCEPT" /> * <category android:name="com.adamrocker.android.simeji.REPLACE" /> * <category android:name="android.intent.category.DEFAULT" /> * 2 此處的REPLACE_KEY的設值.不可隨意更改. * * 官方文檔: * https://simeji.me/blog/make_mushroom */ public class MainActivity extends Activity { private static final String ACTION_INTERCEPT = "com.adamrocker.android.simeji.ACTION_INTERCEPT"; private static final String REPLACE_KEY = "replace_key"; private Button mButton; private String rawContent; private String newContent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init() { mButton = (Button) findViewById(R.id.button); mButton.setOnClickListener(new OnClickListenerImpl()); Intent intent = this.getIntent(); String action = intent.getAction(); if (action != null && ACTION_INTERCEPT.equals(action)) { System.out.println("開始調用文字替換"); rawContent=intent.getStringExtra(REPLACE_KEY); System.out.println("rawContent="+rawContent); } else { System.out.println("沒有調用到文字替換"); } } private class OnClickListenerImpl implements OnClickListener { @Override public void onClick(View v) { Intent data = new Intent(); newContent="hello everybody"; data.putExtra(REPLACE_KEY, newContent); setResult(RESULT_OK, data); finish(); } } }