gpt4 book ai didi

java - 如何让Java从Internet调用数据?从哪里开始呢?

转载 作者:行者123 更新时间:2023-12-01 16:06:02 24 4
gpt4 key购买 nike

你好哦,Android 领域的伟大奇才。我真的需要你的帮助。主要是因为我的小脑袋不知道要开始。我正在尝试从互联网提取数据为主屏幕制作一个小部件。我已经构建了布局:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/widget_bg_normal"
android:clipChildren="false"

>

<TextView
android:id="@+id/text_view"
android:layout_width="100px"
android:layout_height="wrap_content"
android:paddingTop="18px"
android:layout_centerHorizontal="true"
android:textSize="8px"
android:text="158x154 Image downloaded from the internet goes here. Needs to be updated every evening at midnight or unless the button below is pressed. Now if I could only figure out exactly how to do this, life would be good."

/>

<Button
android:id="@+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Get New"
android:layout_below="@+id/scroll_image"
android:layout_centerHorizontal="true"
android:padding="0px"
android:textSize="10px"
android:height="8px"
android:includeFontPadding="false"

/>

</RelativeLayout>

获取了提供者 xml 构建:

<?xml version="1.0" encoding="utf-8"?>

<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="150dip"
android:minHeight="150dip"
android:updatePeriodMillis="10000"
android:initialLayout="@layout/widget"
/>

list 效果很好。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dge.myandroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".myactivty"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- Widget -->
<receiver
android:name=".mywidget"
android:label="@string/app_name"
>
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE"
/>
</intent-filter>

<meta-data
android:name="android.appwidget.widgetprovider"
android:resource="@xml/widgetprovider"
/>
</receiver>
<!-- Widget End -->

</application>

<uses-permission android:name="android.permission.INTERNET" />


<uses-sdk android:minSdkVersion="7" />

</manifest>

当它被调用时,它所调用的数据看起来像这样。它基本上会转到一个使用 php 随机图像的网站:

<html><body bgcolor="#000000">center>    
<a href="http://www.website.com" target="_blank">
<img border="0" src="http://www.webiste.com//0.gif"></a>
<img src="http://www.webiste.com" style="border:none;" />
</center></body></html>

但这就是我被困住的地方。我根本不知道从哪里开始。 java 远远超出了我的小脑袋,我不知道该怎么办。

package com.dge.myandroid;

import android.appwidget.AppWidgetProvider;

public class mywidget extends AppWidgetProvider {



}

维基百科的例子让我更加困惑。我只是不知道从哪里开始。请帮忙。

最佳答案

如果数据托管在网站上,您可以使用 HttpClient在 Android 上发出正确的请求并获取您的数据。

These SO问题可能会有所帮助。

关于java - 如何让Java从Internet调用数据?从哪里开始呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2575380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com