gpt4 book ai didi

java - android studio java web服务每45秒控制一次

转载 作者:行者123 更新时间:2023-12-01 16:15:00 25 4
gpt4 key购买 nike

我必须做一个在 45 秒内与 Web 服务通信的 Android 服务。但我无法通过商业服务或正常服务来做到这一点。 10 分钟后系统自动关闭。我需要帮助。

最佳答案

public class bildirim extends JobService {
int Kul_Id = 0;
String[] sto;
int sayac = 0;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public boolean onStartJob(JobParameters params) {
final ipdatabase dbo = new ipdatabase(getBaseContext());
sto = dbo.ipler(getBaseContext());
database db = new database(bildirim.this);
if (db.dbkontrol()) {
List<String> cr = db.veriListele(2);
if (!cr.isEmpty()) {
Kul_Id = Integer.parseInt(cr.get(4));
}
}
Timer tmr = new Timer();
tmr.schedule(new TimerTask() {
@Override
public void run() {
new arkaplan().execute("http://" + sto[0] + "/Services.asmx/bildirimal?Kul_ID=" + Kul_Id+"&durum=1");

}
},0,30000);
return false;
}

@Override
public boolean onStopJob(JobParameters params) {

return false;
}

@Override
public void onDestroy() {
JobSchedulerService.scheduleJob(getApplicationContext());
super.onDestroy();
}

class arkaplan extends AsyncTask<String, String, String> {
protected String doInBackground(String... params) {
return jsonparser.getdata(params[0]);
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
JSONObject obj = new JSONObject(s);
JSONArray listarray = obj.getJSONArray("list");
JSONObject fistobj;
for (int i = 0; i < listarray.length(); i++) {
fistobj = listarray.getJSONObject(i);
int icon = R.drawable.redwhitefav;
NotificationManagerCompat notifiynm = NotificationManagerCompat.from(bildirim.this);
Notification notifiy = new NotificationCompat.Builder(bildirim.this, CHANNEL_1_ID)
.setSmallIcon(icon)
.setContentTitle(fistobj.getString("Gork_Deger") + ": " + fistobj.getString("Gork_Mstad"))
.setContentText("Tanım: "+ fistobj.getString("Gork_Tanim") + "\n"+ "Tarih: " + fistobj.getString("Gork_Baslangic"))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_REMINDER)
.build();
notifiynm.notify(sayac, notifiy);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}

}

关于java - android studio java web服务每45秒控制一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62424523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com