首页 > 解决方案 > 毕加索图像未通过 USB 调试加载,但在仿真期间工作正常

问题描述

问题:使用 Navigation Drawer Activity 时,Picasso 在仿真期间加载图像,但在 USB 调试期间不加载……非常感谢任何帮助!

更新:答案的解决方案!

这是我的手机没有显示图像的图像,并且模拟器工作正常。我使用 YouTube 缩略图作为在线测试图像: https ://imagizer.imageshack.com/img921/7876/4sd4ak.jpg

当我决定在手机上将它拿出来时,我在一个更大的项目中注意到了这一点,但是在寻找解决方案时,我能够将它隔离到一个新的 Navigation Drawer Layout Activity。

这是我所知道的:

我在 Android Studio 中创建了一个新的 Navigation Drawer Layout Activity 并添加了这个:

1) Build.gradle (Module:app) 依赖:实现 'com.squareup.picasso:picasso:2.5.2'

2) 在我的 Android 清单中:使用权限 android:name="android.permission.INTERNET"

3) 我的 content_main 的 ImageView

4) 在我的 MainActivity 的 onCreate 中:Picasso.with(this).load(" http://img.youtube.com/vi/ek-5vIz_gDw/0.jpg ").into(imageView)

// MainActivity without the additional override functions (no changes)

class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val toolbar: Toolbar = findViewById(R.id.toolbar)
    setSupportActionBar(toolbar)

    val fab: FloatingActionButton = findViewById(R.id.fab)
    fab.setOnClickListener { view ->
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
            .setAction("Action", null).show()
    }
    val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
    val navView: NavigationView = findViewById(R.id.nav_view)
    val toggle = ActionBarDrawerToggle(
        this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
    )
    drawerLayout.addDrawerListener(toggle)
    toggle.syncState()

    navView.setNavigationItemSelectedListener(this)

    Picasso.with(this).load("http://img.youtube.com/vi/ek-5vIz_gDw/0.jpg").into(imageView)

}

还有我的 content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/app_bar_main"
    tools:context=".MainActivity">


<ImageView
        android:layout_width="0dp"
        android:layout_height="0dp" app:srcCompat="@mipmap/ic_launcher_round"
        android:id="@+id/imageView" app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:contentDescription="@string/description"/>

</androidx.constraintlayout.widget.ConstraintLayout>

我在运行时没有收到任何错误消息,只是图像没有加载到 USB 调试 IRL 中。

标签: debuggingkotlinusbpicassodrawerlayout

解决方案


更新:所以我能够让它在我尝试过的所有其他物理手机上运行。然而,为了让它在 Google Pixel 3XL 上运行,我必须做出这个改变。不知道为什么它有任何不同,但它确实有效!

我以前这样做过(仅对我的物理 Pixel 3 不起作用):

    val imageLink = video.link
    Picasso.with(context).load("http://img.youtube.com/vi/$imageLink/0.jpg").into(imageView)

不知道为什么,但这是有效的解决方案:

    val imageLink = "https://img.youtube.com/vi/${video.link}/0.jpg"
    Picasso.with(context).load(imageLink).into(imageView)

希望这可以帮助任何处于同样困境的人!


推荐阅读