Android 在主屏幕应用程序小部件中显示远程图像';s图像视图
我正在学习Android开发的诀窍,所以请原谅我,我正在努力做一些非常基本的事情 我正在尝试从远程URL获取图像并将其放入ImageView。ImageView本身位于应用程序小部件中 但是图像从未加载,并且返回了大量错误 我使用Android Studio的上下文菜单创建了应用程序小部件代码,因此我认为构建块是声音。我在应用程序小部件的布局中创建了一个ImageView,以代替默认的TextView 以下是所有相关代码: 布局/new_app_widget.xml:Android 在主屏幕应用程序小部件中显示远程图像';s图像视图,android,imageview,android-appwidget,Android,Imageview,Android Appwidget,我正在学习Android开发的诀窍,所以请原谅我,我正在努力做一些非常基本的事情 我正在尝试从远程URL获取图像并将其放入ImageView。ImageView本身位于应用程序小部件中 但是图像从未加载,并且返回了大量错误 我使用Android Studio的上下文菜单创建了应用程序小部件代码,因此我认为构建块是声音。我在应用程序小部件的布局中创建了一个ImageView,以代替默认的TextView 以下是所有相关代码: 布局/new_app_widget.xml: <RelativeL
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:contentDescription="@string/content" />
</RelativeLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mike.widgetapptest" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:debuggable="true"
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".NewAppWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/new_app_widget_info" />
</receiver>
</application>
</manifest>
android:debuggable=“true”
错误是什么..错误太多,无法在此评论中列出,因此我将它们放在这里:好吧,因此我提示此“NetworkOnMainThreadException”可能违反了Android编程的基本规则。关于如何在应用程序小部件中的ImageView的特定上下文中将网络移出主线程的任何线索?是的,请参阅此处:好的,谢谢,我似乎已经解决了原始问题。现在我没有得到NetworkOnMainThreadException错误,并且图像文件似乎是从远程URL获取的,我只是无法使用图像更新应用程序小部件的imageview。需要进一步的谷歌搜索。。。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mike.widgetapptest" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:debuggable="true"
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".NewAppWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/new_app_widget_info" />
</receiver>
</application>
</manifest>