如何解决firebase函数在onbootcompleted广播接收器上不起作用
我是Android开发的新手,并且遇到以下问题:
因此在我的应用程序中,我正在使用Firebase实时数据库,并试图设置将在设备启动完成后触发的广播接收器。
我的目标是,随着设备启动完成,广播接收器将检查实时数据库中某条路径中是否列出了某条路由,然后检查的时间是否超过一定时间。
如果列出用户的时间超过15分钟(例如),我希望将其删除,或者使用后延迟功能并在剩余时间之后将其删除。
在模拟器上,该功能可以正常工作,而在我的物理设备上,该功能无法正常工作。
这是我的功能-
private void checkExistent(final Context context,Intent intent) {
final DatabaseReference userref;
userref =
FirebaseDatabase.getInstance().
getReference("users/"+mAuth.getCurrentUser().
getUid()+"/parks/currentlyAtPark/");
Log.d(TAG,"2");
Query checkexistent = userref;
checkexistent.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
Toast.makeText(context,mAuth.getCurrentUser().getUid(),Toast.LENGTH_SHORT).show();
if(snapshot.exists())
{
Toast.makeText(context,"START 3",Toast.LENGTH_SHORT).show();
Log.d(TAG,"3");
final String parkid = snapshot.child("parkid").getValue(String.class);
int chours = snapshot.child("time").child("hours").getValue(int.class);
int days =snapshot.child("time").child("date").getValue(int.class);
int hours = abs(chours- Calendar.getInstance().getTime().getHours());
if(hours>0||days!=Calendar.getInstance().getTime().getDate())
{
//remove
Log.d(TAG,"4");
Toast.makeText(context,"START 4",Toast.LENGTH_SHORT).show();
removeUserFromPark(parkid,userref);
Toast.makeText(context,"data deleted!",Toast.LENGTH_SHORT).show();
}
else
{
if(hours==0)
{
Log.d(TAG,"5");
Toast.makeText(context,"START 5",Toast.LENGTH_SHORT).show();
int cminutes = snapshot.child("time").child("minutes").getValue(int.class);
int minutes = Calendar.getInstance().getTime().getMinutes()-cminutes;
Toast.makeText(context,"Minutes = "+minutes,Toast.LENGTH_SHORT).show();
if(minutes>15)
{
//remove
Log.d(TAG,"6");
Toast.makeText(context,"START 6",Toast.LENGTH_SHORT).show();
removeUserFromPark(parkid,userref);
Toast.makeText(context,Toast.LENGTH_SHORT).show();
}
else
{
if(minutes==0)
{
Log.d(TAG,"7");
Toast.makeText(context,"START 7",Toast.LENGTH_SHORT).show();
Toast.makeText(context,"data Will be deleted within 15mins!",Toast.LENGTH_SHORT).show();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
removeUserFromPark(parkid,userref);
Toast.makeText(context,Toast.LENGTH_SHORT).show();
}
},1000*15*60);
}
else
{
Log.d(TAG,"8");
Toast.makeText(context,"START 8","data Will be deleted!",Toast.LENGTH_SHORT).show();
}
},1000);
}
}
}
}
}
else
{
Log.d(TAG," 0 ");
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
模拟器上的日志-
2020-10-04 17:22:05.652 2606-2606/com.example.myloggin01 D/CompatibilityChangeReporter: Compat change
id reported: 147798919; UID 10151; state: ENABLED
2020-10-04 17:22:05.740 2606-2606/com.example.myloggin01 D/BOOT: 3
2020-10-04 17:22:05.746 2606-2606/com.example.myloggin01 D/BOOT: 5
2020-10-04 17:22:05.829 2606-2606/com.example.myloggin01 D/BOOT: 8
2020-10-04 17:22:07.971 2606-2659/com.example.myloggin01 I/FA: App measurement initialized,version:
31000
2020-10-04 17:22:07.972 2606-2659/com.example.myloggin01 I/FA: To enable debug logging run: adb shell
setprop log.tag.FA VERBOSE
2020-10-04 17:22:07.972 2606-2659/com.example.myloggin01 I/FA: To enable faster debug mode event
我的设备上的日志(小米10英里)-
2020-10-04 17:04:43.060 6741-6741/com.example.myloggin01 D/BOOT: 1
2020-10-04 17:04:43.067 6741-6741/com.example.myloggin01 D/BOOT: 2
2020-10-04 17:04:43.108 6741-6794/com.example.myloggin01 D/NetworkSecurityConfig: No Network Security
Config specified,using platform default
2020-10-04 17:04:43.144 6741-6786/com.example.myloggin01 I/FA: App measurement initialized,version:
31000
2020-10-04 17:04:43.144 6741-6786/com.example.myloggin01 I/FA: To enable debug logging run: adb shell
setprop log.tag.FA VERBOSE
2020-10-04 17:04:43.145 6741-6786/com.example.myloggin01 I/FA: To enable faster debug mode event
我也尝试了这个线程解决方案,但对我没有用: No Network Security Config specified,using platform default - Android Log
先谢谢! :)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。