Tag: 存储

上传图片到Firebase的问题

我试图从手机的图库上传图片到Firebase,但模拟器保持关闭状态,并且没有记录任何错误。 这是我的代码 val PICK_IMAGE_CODE=123 fun loadImage(){ var intent = Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI) startActivityForResult(intent,PICK_IMAGE_CODE) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if(requestCode==PICK_IMAGE_CODE && data!=null && resultCode == RESULT_OK){ val selectedImage=data.data val filePathColum= arrayOf(MediaStore.Images.Media.DATA) val cursor= contentResolver.query(selectedImage,filePathColum,null,null,null) cursor.moveToFirst() val coulomIndex=cursor.getColumnIndex(filePathColum[0]) val picturePath=cursor.getString(coulomIndex) cursor.close() uploadImage(BitmapFactory.decodeFile(picturePath)) } } var DownloadURL:String?="" fun uploadImage(bitmap:Bitmap){ adapter!!.notifyDataSetChanged() var currentUser […]

Firebase存储的OnSuccessListener回调没有调用

通过Firebase存储上传文件时,onSuccess方法不会调用。 我目前正在运行Android Studio 3.0 Canary 2,其中包含“com.google.firebase:firebase-storage:10.2.6”。 fun uploadImage(pathToImage: String, downloadCallback: FirebaseCallback<String?>) { val file = Uri.fromFile(File(pathToImage)) val ref = mStorRef.child("images/"+file.lastPathSegment) ref.putFile(file).addOnSuccessListener { object : OnSuccessListener<UploadTask.TaskSnapshot> { override fun onSuccess(taskSnapshot: UploadTask.TaskSnapshot?) { val url = taskSnapshot?.downloadUrl Log.d("FirebaseManager", "Upload Successful") downloadCallback.callback(url.toString()) } } } }

调用File.createNewFile()时,权限被拒绝 Android的

我试图创建一个图像文件到外部存储来分享它。 但在尝试下面的代码时,我有一些错误 var icon: Bitmap = BitmapFactory.decodeResource(resources, R.drawable.namelogo) val shareIntent = Intent(Intent.ACTION_SEND) shareIntent.type = "image/*" val bytes = ByteArrayOutputStream() icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes) val path = File.separator + "temporary_file.jpg" val f = File(Environment.getExternalStorageDirectory().toString(), path) try { if (!f.parentFile.exists()) f.parentFile.mkdirs() if (!f.exists()) f.createNewFile() f.createNewFile() val fo = FileOutputStream(f) fo.write(bytes.toByteArray()) } catch (e: IOException) { Log.e("path = ", […]

如何将Firebase中的文本文件读取到Android应用程序

我正在开发基于内容的Android应用程序。我使用Firebase上传所有文本文件(在rtf或doc文件中)。当我将一个文本文件上传到Firebase后,我创建了一个详细的活动,从firebase下载文件,但文本文件不读,它什么也没有显示。这里是我的Kotlin代码… class detailOne : AppCompatActivity() { private var mTextView : TextView? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.detailone) val myButton = findViewById(R.id.butOne) as Button mTextView = findViewById(R.id.myText) as TextView FirebaseApp.initializeApp(this) val storage = FirebaseStorage.getInstance() val storageRef = storage.getReferenceFromUrl("gs://yehwot-eta.appspot.com/story.rtf") try { val localFile = File.createTempFile("text", "rtf") storageRef.getFile(localFile).addOnSuccessListener { }.addOnFailureListener { print("Connection is Lost!Please Try […]