嗨,我在几乎完整的程序中遇到了一个大问题,我无法将我的字符串转换为整数并将其进一步累加。我知道这很容易,并且可以使用public class SMSService extends Service {
private PowerManager.WakeLock mWakeLock = null;
private boolean skip = true;
SmsManager mSmsManager;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mSmsManager = SmsManager.getDefault();
SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
mWakeLock.acquire();
timer(minutes, true);
if (Build.VERSION.SDK_INT >= 26) {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification mNotification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle(getString(R.string.notification_title))
.setContentText(getString(R.string.notification_text))
.setSmallIcon(R.drawable.ic_local)
.setContentIntent(mPendingIntent)
.build();
startForeground(1, mNotification);
}
return START_NOT_STICKY;
}
void timer(final int minutes, final boolean close) {
CountDownTimer cdt = new CountDownTimer(minutes * 60 * 1000 + 15000, minutes * 60 * 1000) {
@Override
public void onTick(long millisUntilFinished) {
if (!skip) {
mSmsManager.sendTextMessage(number, null, sms_body, null, null);
}
skip = false;
}
@Override
public void onFinish() {
if (!close) {
skip = true;
timer(minutes, true);
}
else {
stopSelf();
}
}
};
cdt.start();
}
}
和parsetInt()
来完成,但是这让我头疼。请kndliy查看我的代码并帮助我,这样我就不会{{1} }
代码在这里:
number()
谢谢...
答案 0 :(得分:-1)
function myFunction(){
var operator = document.getElementById("operator").value;
var Quantity = document.getElementById("quantity").value;
if(operator.trim().length&&Quantity.trim().length){
var GetQuantity = Number(Quantity);
var testing = parseInt(GetQuantity);
if(operator == '+') {
testing = testing + 1;
}
else {
testing = testing - 1;
}
alert(testing);
document.getElementById("result").innerHTML=testing;
} else {
document.getElementById("result").innerHTML="<b style='color:"+
"red;'>Please enter an operator and a quantity!</b>";
}
}
<html>
<head>
</head>
<body>
<label>
Operator:
<input type="text" id="operator"/>
</label>
<br/>
<label>
Quantity:
<input type="text" id="quantity"/>
</label>
<br/>
<button onClick="myFunction()">
Do The Math
</button>
<br/>
Result:
<br/>
<span id="result"></span>
</body>
</html>