我正在开发一个小型Android应用程序,我希望在其中具有Geolocation功能.我想要编码的是一种服务,它提供用户的更新位置,无论他们是否正在使用我的应用程序.
我知道,如果我不断检查用户的位置,它会耗尽设备的电池,所以我想要很好的解决方案.例如,每隔5或10分钟给我更新一次.我已经阅读了很多这个问题,但我想得到一个好的解决方案.
我读了这个页面,如果用户正在使用我的应用程序,但如果用户没有使用我的应用程序那么这是一个很好的解决方案,那么我该怎么办?我该如何解决这一挑战?
我有一个数据库,我需要在某一天删除,我该如何执行此任务?我找到了这个 :
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
synchronized public void run() {
\\ here your todo;
}
}}, TimeUnit.MINUTES.toMillis(1), TimeUnit.MINUTES.toMillis(1));
Run Code Online (Sandbox Code Playgroud)
但是我不确定它是否会在到期日之前"保存任务".谢谢
我有以下代码.应该以一定的间隔在logcat中发送消息但是不起作用.stackoverflow上有很多类似的帖子,但我无法弄清楚问题.在某处可以帮助我的brainiac吗?
<receiver android:name="BoopoohooAlarmReceiver"></receiver>
public void startAlarmManager(long interval){
Context context = getApplicationContext();
Intent intent = new Intent(context, BoopoohooAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);
Log.i(DEBUG, "hollaa");
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, pendingIntent);
}
public class BoopoohooAlarmReceiver extends BroadcastReceiver {
private final String DEBUG = "BoopoohooAlarmReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(DEBUG, "onReceive");
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在开发Android应用程序,其中我卡在一点,
我想做的是,
当用户在一天内第一次启动应用程序时,我想向他显示一些警报.当他在同一天第二次打开应用程序时,它将不会收到警报.(他只会在第一天发布应用程序时收到警报).
第二天,如果他再次第一次打开应用程序,他会得到警报,第二次他不会得到警报.
简而言之:用户应该在每天的首次发布时获得警报.
任何想法,我该怎么做到这一点?提前致谢.
我的Android应用程序中有些东西需要每天更新一次.
我认为这很简单,但我不知道我需要格式化日期和时间的格式(如果需要时间)以及如何检查今天是否已完成更新(今天是在00:01 am到23之间:用户当地时间下午59点).如果今天已经完成更新,则不应该进行更新.
这是我所知道的怎么做:
我正在构建一个应用程序,我需要安排一个通知,记住用户访问该应用程序.我需要在上次使用应用程序之前一个月显示此通知
我有一个按钮,客户可以通过该按钮领取他的每日奖励.我希望每天只点击一次该按钮.我怎么能这样做?
我不知道如何实现这个功能
我知道我可以设置它View.gone但我想让它在第二天再次可见.点击按钮可以得到一天的时间
这是点击我的按钮我该怎么办?
@Override
public void onClick(View v) {
super.onClick(v);
switch (v.getId()) {
case R.id.creditClaimBT: {
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
帮助将不胜感激.
这是我的代码:
@Override
public void onCreate() {
super.onCreate();
//Log.i("TAG", "ovdje smo");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("alo", "bre");
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
oldCellID = cellLocation.getCid();
while( true ){
Log.i("jesmo li tu",""+oldCellID);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Toast.makeText(this, "Kupimo cell ID OLD" + oldCellID, Toast.LENGTH_SHORT).show();
telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
cellLocation = (GsmCellLocation) telephonyManager.getCellLocation();
newCellID = cellLocation.getCid();
if(oldCellID != newCellID){
//TODO uzmi lokaciju + spremi u bazu
Log.i("usli u petlju", …Run Code Online (Sandbox Code Playgroud) android ×8
alarmmanager ×1
batterylevel ×1
button ×1
click ×1
date ×1
geolocation ×1
java ×1
listener ×1
schedule ×1
service ×1