首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Kotlin:照相机只在模拟器(Android 8)上拍照,不正确地显示链接到实时存储数据库中的照片

Kotlin:照相机只在模拟器(Android 8)上拍照,不正确地显示链接到实时存储数据库中的照片
EN

Stack Overflow用户
提问于 2022-03-20 18:06:24
回答 1查看 82关注 0票数 0

我正在以instagram的形式编写一个应用程序(我学习YouTube的课程,他们在Android8上创建它,我试图在Android10上做同样的事情),我只认识Kotlin几周了。已经实施了很多。但正是在火场中出现了问题。两个问题:

  1. 在应用程序中注册了一个用户,并将他的文本数据保存在firebase中--我可以从任何设备中这样做。通过Android 8上的仿真器-我可以拍摄一张照片,一切都正常工作,甚至链接,以改变个人资料照片是正确的显示。还有一个ShareActivity文件,用户可以在“墙壁”上共享一张照片,问题是照片出现在google的存储中,而在实时数据库中,该照片的链接被写成"com.google.firebase.storage.UploadTask $TaskSnapshot@46529a6",但应该以链接"https://firebasestorage.googleapis.com/v0/b/instapirate...的形式写成“,而配置文件照片是正确显示的,即:不,照片是不可见的。如何修复此缺陷?我从仿真器和数据库附加了一张照片:

  1. 还有另外一个问题,就是在Instagram仿真器中的安卓8上,我被要求获得相机的许可,我允许它和相机工作,拍照,一切都很好。而在android 10中,不请求对相机的许可,因此相机会打开,拍照,但不能保存照片(当我单击“保存”按钮时重新打开)。几次,如果我快速戳一下按钮--有时保存照片会有帮助,但这种情况在百万中有一种情况下会发生。这并不是因为相机的分辨率。我附上以下代码:AndroidManifest

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.instapirate">


    <uses-feature android:name="android.hardware.camera"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.INSTApirate" >

        <activity
            android:name=".activities.MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".activities.SearchActivity" />
        <activity android:name=".activities.ShareActivity" />
        <activity android:name=".activities.LikesActivity" />
        <activity android:name=".activities.ProfileActivity" />
        <activity
            android:name=".activities.EditProfileActivity"
            android:exported="true" />
        <activity
            android:name=".activities.LoginActivity"
            android:windowSoftInputMode="stateVisible|adjustResize" >
        </activity>
        <activity
            android:name=".activities.RegisterActivity"
            android:windowSoftInputMode="stateVisible|adjustResize" >
        </activity>
        <activity android:name=".activities.ProfileSettingsActivity" />
        <activity android:name=".activities.AddFriendsActivity"/>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.example.instapirate.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>
</manifest>

配置文件是使用EditProfileActivity文件编辑的。下面有一段特定的代码,用于拍照和更改用户的化身,这里的链接工作,并以正常的形式加载到存储和RealtimeDatabase中,但是在Android 10上,照片也没有被拍摄,相机也被重置:

代码语言:javascript
运行
复制
 private lateinit var mUser: User
    private lateinit var mFirebase: FirebaseHelper
    private lateinit var mPendingUser: User
    private lateinit var mCamera: CameraHelper

    @SuppressLint("MissingSuperCall")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == mCamera.REQUEST_CODE && resultCode == RESULT_OK) {
            mFirebase.uploadUserPhoto(mCamera.imageUri!!) {
                mFirebase.storageUid().addOnCompleteListener {
                    val photoUrl = it.result.toString()
                    mFirebase.updateUserPhoto(photoUrl){
                        mUser = mUser.copy(photo = photoUrl)
                        profile_image.loadUserPhoto(mUser.photo)
                    }
                }
            }
        }
    }

loadUserPhoto位于一个单独的utils文件中,其中存储了所有实用程序:

代码语言:javascript
运行
复制
fun ImageView.loadUserPhoto(photoUrl: String?) =
    ifNotDestroyed {
        GlideApp.with(this).load(photoUrl).fallback(R.drawable.person).into(this)
    }

参与上述代码的远程类:CameraHelper

代码语言:javascript
运行
复制
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import androidx.core.content.FileProvider
import java.io.File
import java.text.SimpleDateFormat
import java.util.*

class CameraHelper(private val activity: Activity) {
    var imageUri: Uri? = null
    val REQUEST_CODE = 1
    private val simpleDateFormat = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US)

    fun takeCameraPicture() {
        val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        if (intent.resolveActivity(activity.packageManager) != null) {
            val imageFile = createImageFile()
            imageUri = FileProvider.getUriForFile(activity,
                "com.example.instapirate.fileprovider",
                imageFile)
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
            activity.startActivityForResult(intent, REQUEST_CODE)
        }
    }
    private fun createImageFile(): File {
        val storageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
        return File.createTempFile(
            "JPEG_${simpleDateFormat.format(Date())}_",
            ".jpg",
            storageDir
        )
    }
}

FirebaseHelper

代码语言:javascript
运行
复制
import android.app.Activity
import android.net.Uri
import com.example.instapirate.activities.showToast
import com.google.firebase.auth.AuthCredential
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
import com.google.firebase.storage.UploadTask

class FirebaseHelper(private val activity: Activity) {
    val auth: FirebaseAuth = FirebaseAuth.getInstance()
    val database: DatabaseReference = FirebaseDatabase.getInstance().reference
    val storage: StorageReference = FirebaseStorage.getInstance().reference

    fun storageUid() = storage.child("users/${auth.currentUser!!.uid}/photo/").downloadUrl

    fun uploadUserPhoto(photo: Uri, onSuccess: (UploadTask.TaskSnapshot) -> Unit) {
        storage.child("users/${currentUid()!!}/photo").putFile(photo)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess(it.result!!)
                } else {
                    activity.showToast(it.exception!!.message!!)
                }
            }
    }

    fun updateUserPhoto(photoUrl: String, onSuccess: () -> Unit) {
        database.child("users/${currentUid()!!}/photo").setValue(photoUrl)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess()
                } else {
                    activity.showToast(it.exception!!.message!!)
                }
            }
    }

    fun updateUser(updates: Map<String, Any?>, onSuccess: () -> Unit) {
        database.child("users").child(currentUid()!!).updateChildren(updates)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess()
                } else {
                    activity.showToast(it.exception!!.message!!)
                }
            }
    }

    fun updateEmail(email: String, onSuccess: () -> Unit) {
        auth.currentUser!!.updateEmail(email).addOnCompleteListener {
            if (it.isSuccessful) {
                onSuccess()
            } else {
                activity.showToast(it.exception!!.message!!)
            }
        }
    }

    fun reauthenticate(credential: AuthCredential, onSuccess: () -> Unit) {
        auth.currentUser!!.reauthenticate(credential).addOnCompleteListener {
            if (it.isSuccessful) {
                onSuccess()
            } else {
                activity.showToast(it.exception!!.message!!)
            }
        }
    }

    fun currentUserReference(): DatabaseReference =
        database.child("users").child(currentUid()!!)

    fun currentUid(): String? =
        auth.currentUser?.uid

}

还有一个实现将照片上传到提要的ShareActivity文件,这就是Firebase出现问题的地方,因为链接是在这里以不正确的形式显示的(提要的屏幕截图在上面)。如果照片是通过仿真器在Android 8上拍摄的,就会发生这种情况。(在Android 10手机上,保存照片后,相机重新打开,我不得不再拍一次照片,等等。)

代码语言:javascript
运行
复制
class ShareActivity : BaseActivity(2) {
    private val TAG = "ShareActivity"
    private lateinit var mCamera: CameraHelper
    private lateinit var mFirebase: FirebaseHelper
    private lateinit var mUser: User

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_share)
        Log.d(TAG, "onCreate")

        mFirebase = FirebaseHelper(this)
        mCamera = CameraHelper(this)
        mCamera.takeCameraPicture()

        back_image.setOnClickListener{finish()}
        share_text.setOnClickListener{ share()}

        mFirebase.currentUserReference().addValueEventListener(ValueEventListenerAdapter{
            mUser = it.asUser()!!
        })
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == mCamera.REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                GlideApp.with(this).load(mCamera.imageUri).centerCrop().into(post_image)
            } else {
                finish()
            }
        }
    }

    private fun share() {
        val imageUri = mCamera. imageUri
        if (imageUri != null) {
            val uid = mFirebase.currentUid()!!
            mFirebase.storage.child("users").child(uid).child("images")
                .child(imageUri.lastPathSegment.toString()).putFile(imageUri).addOnCompleteListener{
                    if (it.isSuccessful){
                        val imageDownloadUrl = it.result!!.toString()
                        mFirebase.database.child("images").child(uid).push()
                            .setValue(imageDownloadUrl)
                            .addOnCompleteListener {
                                if (it.isSuccessful) {
                                    mFirebase.database.child("feed-posts").child(uid)
                                        .push()
                                        .setValue(mkFeedPost(uid, imageDownloadUrl))
                                        .addOnCompleteListener {
                                            if (it.isSuccessful) {
                                                startActivity(Intent(this,
                                                    ProfileActivity::class.java))
                                                finish()
                                            }
                                        }
                                } else {
                                    showToast(it.exception!!.message!!)
                                }
                            }
                    } else {
                        showToast(it.exception!!.message!!)
                    }
                }
        }
    }

    private fun mkFeedPost(uid: String, imageDownloadUrl: String): FeedPost {
        return FeedPost(
            uid = uid,
            username = mUser.username,
            image = imageDownloadUrl,
            caption = caption_input.text.toString(),
            photo = mUser.photo
        )
    }
}

当试图在android 10上保存照片时,以下文本出现在Debug中(由于限制而无法显示整个错误,但我认为这是错误的一个重要部分):

代码语言:javascript
运行
复制
2022-03-20 19:05:55.711 29351-29351/? I/ple.instapirat: Late-enabling -Xcheck:jni
2022-03-20 19:05:55.855 29351-29351/? E/ple.instapirat: Unknown bits set in runtime_flags: 0x8000
2022-03-20 19:05:56.943 29351-29351/com.example.instapirate I/Perf: Connecting to perf service.
2022-03-20 19:05:57.016 29351-29351/com.example.instapirate I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2022-03-20 19:05:57.126 29351-29351/com.example.instapirate D/FirebaseAuth: Notifying id token listeners about user ( PjHBujbeapTQxmLl4TgzhgOTzjo2 ).
2022-03-20 19:05:57.158 29351-29351/com.example.instapirate I/FirebaseInitProvider: FirebaseApp initialization successful
2022-03-20 19:05:57.194 29351-29422/com.example.instapirate I/DynamiteModule: Considering local module com.google.android.gms.measurement.dynamite:69 and remote module com.google.android.gms.measurement.dynamite:67
2022-03-20 19:05:57.194 29351-29422/com.example.instapirate I/DynamiteModule: Selected local version of com.google.android.gms.measurement.dynamite
2022-03-20 19:05:57.263 29351-29424/com.example.instapirate E/Perf: Fail to get file list com.example.instapirate
2022-03-20 19:05:57.264 29351-29424/com.example.instapirate E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2022-03-20 19:05:57.427 29351-29425/com.example.instapirate I/FA: App measurement initialized, version: 60000
2022-03-20 19:05:57.427 29351-29425/com.example.instapirate I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2022-03-20 19:05:57.428 29351-29425/com.example.instapirate I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.example.instapirate
2022-03-20 19:05:57.428 29351-29425/com.example.instapirate D/FA: Debug-level message logging enabled
2022-03-20 19:05:57.554 29351-29351/com.example.instapirate W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@6dd3e0e
2022-03-20 19:05:57.825 29351-29351/com.example.instapirate W/ple.instapirat: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2022-03-20 19:05:57.827 29351-29351/com.example.instapirate W/ple.instapirat: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2022-03-20 19:05:58.076 29351-29351/com.example.instapirate D/ShareActivity: onCreate
2022-03-20 19:05:58.332 29351-29425/com.example.instapirate I/FA: Tag Manager is not found and thus will not be used
2022-03-20 19:05:58.417 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.441 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.443 29351-29511/com.example.instapirate I/chatty: uid=10260(com.example.instapirate) glide-source-th identical 1 line
2022-03-20 19:05:58.444 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.451 29351-29519/com.example.instapirate D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2022-03-20 19:05:58.467 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.472 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.571 29351-29439/com.example.instapirate I/AdrenoGLES: QUALCOMM build                   : 7331a27, Ieeb4a86f7b
    Build Date                       : 11/13/19
    OpenGL ES Shader Compiler Version: EV031.27.05.02
    Local Branch                     : 
    Remote Branch                    : 
    Remote Branch                    : 
    Reconstruct Branch               : 
2022-03-20 19:05:58.571 29351-29439/com.example.instapirate I/AdrenoGLES: Build Config                     : S L 8.0.12 AArch64
2022-03-20 19:05:58.608 29351-29439/com.example.instapirate I/AdrenoGLES: PFP: 0x005ff113, ME: 0x005ff066
2022-03-20 19:05:58.618 29351-29439/com.example.instapirate W/AdrenoUtils: <ReadGpuID_from_sysfs:194>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
2022-03-20 19:05:58.618 29351-29439/com.example.instapirate W/AdrenoUtils: <ReadGpuID:218>: Failed to read chip ID from gpu_model. Fallback to use the GSL path
2022-03-20 19:05:58.668 29351-29439/com.example.instapirate W/Gralloc3: mapper 3.x is not supported
2022-03-20 19:05:58.751 29351-29351/com.example.instapirate W/Glide: Load failed for content://com.example.instapirate.fileprovider/images/JPEG_20220320_190558_2535596221289941323.jpg with size [204x204]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 3 causes:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AutoCloseInputStream->Object->Drawable}, LOCAL
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->Bitmap->Drawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->BitmapDrawable->Drawable}
      Cause (2 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{ParcelFileDescriptorInner->Object->Drawable}, LOCAL
    There were 2 causes:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptorInner->Bitmap->Drawable}
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
        Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptorInner->BitmapDrawable->Drawable}
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
      Cause (3 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AssetFileDescriptor->Object->Drawable}, LOCAL
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AssetFileDescriptor->Bitmap->Drawable}
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
      Cause (4 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{HierarchicalUri->Object->Drawable}, LOCAL
        Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{HierarchicalUri->Drawable->Drawable}
        Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{HierarchicalUri->Bitmap->Drawable}
2022-03-20 19:05:58.753 29351-29351/com.example.instapirate I/Glide: Root cause (1 of 3)
    java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder.decode(VideoDecoder.java:185)
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92)
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70)
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59)
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76)
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57)
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:524)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:488)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:474)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:426)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:390)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataReadyInternal(SourceGenerator.java:148)
        at com.bumptech.glide.load.engine.SourceGenerator$1.onDataReady(SourceGenerator.java:76)
        at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:52)
        at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:434)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:390)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataReadyInternal(SourceGenerator.java:148)
        at com.bumptech.glide.load.engine.SourceGenerator$1.onDataReady(SourceGenerator.java:76)
        at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:52)
        at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
     Caused by: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
        at android.media.MediaMetadataRetriever.setDataSource(Native Method)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:142)
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder$ParcelFileDescriptorInitializer.initialize(VideoDecoder.java:306)
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder$ParcelFileDescriptorInitializer.initialize(VideoDecoder.java:301)
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder.decode(VideoDecoder.java:173)
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92) 
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70) 
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59) 
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76) 
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57) 
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:524) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:488) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:474) 

如果需要从代码中获得更多必要的数据,那么我可以编辑文章并添加它们(在我看来,我已经附加了太多的代码,对不起,但这一切都很重要)。我希望有人能帮我解决至少一个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-21 10:59:33

刚将以下代码添加到FirebaseHelper中:

代码语言:javascript
运行
复制
    fun uploadSharePhoto(localPhotoUrl: Uri, onSuccess: (UploadTask.TaskSnapshot) -> Unit) =
        storage.child("users/${auth.currentUser!!.uid}").child("images")
            .child(localPhotoUrl.lastPathSegment!!)
            .putFile(localPhotoUrl)
            .addOnCompleteListener {
                if (it.isSuccessful)
                    onSuccess(it.result!!)
                else
                    activity.showToast(it.exception!!.message!!)
            }

    fun addSharePhoto(globalPhotoUrl: String, onSuccess: () -> Unit) =
        database.child("images").child(auth.currentUser!!.uid)
            .push().setValue(globalPhotoUrl)
            .addOnComplete { onSuccess() }

    private fun Task<Void>.addOnComplete(onSuccess: () -> Unit) {
        addOnCompleteListener {
            if (it.isSuccessful)
                onSuccess()
            else
                activity.showToast(it.exception!!.message!!)
        }
    }

ShareActivity中,编辑了share()函数:

代码语言:javascript
运行
复制
    private fun share() {
        val imageUri = mCamera.imageUri
        if (imageUri != null) {
            mFirebase.uploadSharePhoto(imageUri) {
                it.metadata!!.reference!!.downloadUrl.addOnSuccessListener {
                    mFirebase.addSharePhoto(it.toString()) {
                        mFirebase.database.child("feed-posts").child(mFirebase.auth.currentUser!!.uid)
                            .push()
                            .setValue(mkFeedPost(mFirebase.auth.currentUser!!.uid, it.toString()))
                            .addOnCompleteListener {
                                if (it.isSuccessful) {
                                    startActivity(Intent(this,
                                        ProfileActivity::class.java))
                                    finish()
                                }
                            }
                    }
                }
            }
        }
    }

现在所有的链接都是正确的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71549354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档