debugging - 毕加索图像未通过 USB 调试加载,但在仿真期间工作正常
问题描述
问题:使用 Navigation Drawer Activity 时,Picasso 在仿真期间加载图像,但在 USB 调试期间不加载……非常感谢任何帮助!
更新:答案的解决方案!
这是我的手机没有显示图像的图像,并且模拟器工作正常。我使用 YouTube 缩略图作为在线测试图像: https ://imagizer.imageshack.com/img921/7876/4sd4ak.jpg
当我决定在手机上将它拿出来时,我在一个更大的项目中注意到了这一点,但是在寻找解决方案时,我能够将它隔离到一个新的 Navigation Drawer Layout Activity。
这是我所知道的:
- 我所有的 SDK、AndroidStudio、GooglePixel 3XL Phone (IRL) 都已更新
- 在 Android Studio 中无效/重新启动我的 Cashes
- 迁移到 AnrdroidX 时也会出现此问题
- 使用模拟器时,所有 Android 手机都按预期工作,但不是我的物理 Google Pixel 3XL 上的 USB 调试
- 更新:我让它通过 USB 在我的三星 Galaxy 7 上工作!
- 其他布局(如 Empty 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 中。
解决方案
更新:所以我能够让它在我尝试过的所有其他物理手机上运行。然而,为了让它在 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)
希望这可以帮助任何处于同样困境的人!
推荐阅读
- react-native - React Native 如何在不转到该屏幕的情况下将道具传递到另一个屏幕
- gensim - Mallet 中的一致性和诊断文件
- java - UDP 服务器无法正确发回音频
- c++ - 如何用随机值填充数组
- kotlin - 带有 catch 运算符的 Kotlin Flow 仍然完成
- python - 我的 colab 笔记本崩溃了,我该如何解决?
- php - 成功提交后隐藏登录表单
- google-apps-script - 我不知道为什么这个脚本忽略了向某些收件人发送电子邮件
- laravel - 卡到尽头怎么回线?
- python - 如何将边界框转换为 COCO.json 中的实例分割?