我正在为Worklight编写原生的Android代码插件,它看起来像:
public class Getimeiplugin extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
throws JSONException {
if (action.equals("getimeiand")){
try {
String Strgetimei = getemei(); ///How to call public String get imei here
final String responseText = Strgetimei + args.getString(0);
cordova.getThreadPool().execute(new Runnable() {
public void run() {
callbackContext.success(responseText); // Thread-safe.
}
});
} catch (JSONException e){
callbackContext.error("Failed to parse parameters");
}
return true;
}
return false;
}
public String getemei(Context context)
{
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = mTelephonyMgr.getDeviceId();
return imei;
}
}
我不知道如何致电public String getimei(Context context)
,请有人帮助我吗?
答案 0 :(得分:1)
尝试更改此行:
String Strgetimei = getemei();
到此:
String strGetimei = getemei(this.cordova.getActivity().getApplicationContext());
或者这个:
String strGetimei = getemei(callBackContext);
我认为其中一个会起作用。
然后你必须改变这一行:
final String responseText = Strgetimei + args.getString(0);
到此:
final String responseText = strGetimei + args.getString(0);
绝对花一些时间阅读变量命名约定。你不应该以大写字母开头命名变量。这是为Classes保留的。