我有一个android应用程序,它使用firebase存储来保存图像,老实说,我不知道它以前有什么问题(没有真正改变任何东西(,当我放置断点时,它也可以工作,但当我只使用该应用程序时,图像不会被保存。
以下是我如何将它们上传到firebase:
fun writeRoute(route: TrackerModel) {
val user = User()
val routeUser = database.getReference("/Routes").child(user.getUserEmailForDatabase())
routeUser.child(route.guid.toString()).child("userEmail").setValue(route.userEmail)
routeUser.child(route.guid.toString()).child("locations").setValue(route.getLocations())
routeUser.child(route.guid.toString()).child("totalDistance").setValue(route.getTotalDistance())
routeUser.child(route.guid.toString()).child("startDate").setValue(route.startDate)
routeUser.child(route.guid.toString()).child("endDate").setValue(route.endDate)
routeUser.child(route.guid.toString()).child("guid").setValue(route.guid)
routeUser.child(route.guid.toString()).child("markers").setValue(route.getAllMarkers().map { marker -> marker.key })
routeUser.child(route.guid.toString()).child("name").setValue(route.name)
// write markers with bitmaps
val images = storage.getReference("/Images")
val currentRouteImages = images.child(route.guid.toString())
// k is of type LatLng and v is a Bitmap
for ((k,v) in route.getAllMarkers()){
if (v != null){
val value = "PromenApp_${route.guid}_${k.latitude}_${k.longitude}.JPG"
val baos = ByteArrayOutputStream()
v.compress(Bitmap.CompressFormat.JPEG,100,baos)
val data = baos.toByteArray()
currentRouteImages.child(value).putBytes(data)
.addOnFailureListener{
println("error has occured while writing to storage")
it.printStackTrace();
}.addOnSuccessListener {
Log.d("Storage", "Image uploaded succesfully")
}
}
}
}
这是我称之为的方法
btnStopTracking.setOnClickListener{
if (tracking) {
val popup = AlertDialog.Builder(this)
val inflater = layoutInflater
val view = inflater.inflate(R.layout.save_route, null)
popup.setView(view)
.setPositiveButton("Yes", DialogInterface.OnClickListener { popup, _ ->
val textview = view.findViewById<EditText>(R.id.route_name)
controller.setName(textview.text.toString())
controller.stopTracking()
controller.writeToDatabase()
Log.d("DB", "Written to database")
// redirect to home page
startActivity(Intent(this, Home::class.java));
})
.setNegativeButton("No", DialogInterface.OnClickListener { popup, _ ->
controller.stopTracking();
// redirect to home page
startActivity(Intent(this, Home::class.java));
})
popup.show()
}else{
// add current point as starting point
controller.addLocation(currentLocation);
tracking = true;
startStopButton.setImageResource(R.drawable.stop_tracking)
controller.startTracking()
}
}
谢谢你能给我的任何帮助。
stacktrace在评论中要求,但我不认为它与火球有关
java.lang.IllegalArgumentException: Service not registered: lu@ef67976
at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1562)
at android.app.ContextImpl.unbindService(ContextImpl.java:1692)
at android.content.ContextWrapper.unbindService(ContextWrapper.java:717)
at ci.f(:com.google.android.gms.dynamite_measurementdynamite@204516068@20.45.16 (100700-0):1)
at ci.d(:com.google.android.gms.dynamite_measurementdynamite@204516068@20.45.16 (100700-0):2)
at lv.E(:com.google.android.gms.dynamite_measurementdynamite@204516068@20.45.16 (100700-0):9)
at lf.a(:com.google.android.gms.dynamite_measurementdynamite@204516068@20.45.16 (100700-0):3)
at ef.run(:com.google.android.gms.dynamite_measurementdynamite@204516068@20.45.16 (100700-0):3)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at iy.run(:com.google.android.gms.dynamite_measurementdynamite@204516068@20.45.16 (100700-0):5)
问题是,在我保存它之后,调用了另一个想要读取它的函数,这导致了问题。