我收到一条错误消息:SharedPreferences.Editor 类型中的 putString(String, String) 方法不适用于参数 (String, char[])
...而且我不确定为什么会出现问题或如何纠正它。
我在想我可以使用:
editor.putLong("0", data);
但这只会导致:
SharedPreferences.Editor 类型中的 putLong(String, long) 方法不适用于参数 (String, char[])
线路发生错误:
editor.putLong("0", 数据);
资源:
public class DataCountService extends Service {
String text = "USR;1";
String ERROR = Constants.PREFS_NAME;
private Timer timer = new Timer();
private long period;
private long delay_interval;
public static final String swappedMdn(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx
.getSystemService(Context.TELEPHONY_SERVICE);
// Extract the phone number from the TelephonyManager instance
String mdn = tm.getLine1Number();
// Insure MDN is 10 characters
if (mdn.length() < 10 || mdn == null)
mdn = "0000000000";
// Extract last 10 digits of MDN
if (mdn.length() > 10)
mdn = mdn.substring(mdn.length() - 10, mdn.length());
char data[] = mdn.toCharArray();
char digit;
for (int index = 0; index < mdn.length() - (mdn.length()) % 2; index += 2) {
digit = data[index];
data[index] = data[index + 1];
data[index + 1] = digit;
Intent i = new Intent(ctx, DataCountService.class);
SharedPreferences settings = ctx.getSharedPreferences(Constants.PREFS_NAME, 0);
Editor editor = settings.edit();
editor.putString("0", data);
editor.commit();
}