使用native.js可以在html页面的javascript中取得SharedPreferences的数据吗?我写了一个demo确没有显示数据,我确信SharedPreferences是有值的,难道不能这么用吗!
l***@foxmail.com
- 发布:2016-12-01 09:28
- 更新:2016-12-13 15:56
- 阅读:1030
你好,本人初次涉及native.js,有一个问题:
分类:Native.js
1 个回复
l***@foxmail.com (作者)
function getDataFromAndroid(){
var mainActivity = plus.android.runtimeMainActivity();
var Toast = plus.android.importClass("android.widget.Toast");
var Context = plus.android.importClass("android.content.Context");
var SharedPreferences = plus.android.importClass("android.content.SharedPreferences");
var sp = mainActivity.getSharedPreferences("data",Context.MODE_PRIVATE);
var value1 = plus.android.invoke(sp,"getString","data1","");
var value2 = plus.android.invoke(sp,"getString","data2","");
var toast = Toast.makeText(mainActivity,"data1:"+value1+"\n"+"data2:"+value2,Toast.LENGTH_SHORT);
toast.show();
}
用var value1 = plus.android.invoke(sp,"getString","data1","");
而不是用var value1 = sp.getString("data1","");