我需要把html页的数据传到原生activity中,这个怎么传,在activity里怎么接收
阿黎
- 发布:2016-08-18 18:38
- 更新:2017-05-08 17:48
- 阅读:2235
Html5页面怎么传值到Activity原生页面
分类:HTML5+
赵梦欢 - 专注前端,乐于分享!
html页面:
<button id="btn" type="button">跳转到Activity</button>
<script type="text/javascript">
document.querySelector('#btn').addEventListener('click',function () {
var main = plus.android.runtimeMainActivity();
var Intent = plus.android.importClass("android.content.Intent");
var intent = new Intent(main.getIntent());
intent.setClassName(main, "io.dcloud.Test");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("extra", "这是页面传来的值!");
main.startActivity(intent);
})
</script>
原生activity页面:
public class Test extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Intent intent = getIntent();
String extraStr = intent.getStringExtra("extra");
TextView textView = (TextView)findViewById(R.id.textView);
textView.setText(extraStr);
}
}
7***@qq.com
那要是Activity页面怎么传值到Html5原生页面呢???
2017-02-10 10:58