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

标签 java android widget

你好哦,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/

相关文章:

java - 如何在空布局中添加滚动条?

java - 假装客户端响应验证

java - 保存裁剪后的图像后为 "Unable to resume activity"- Android

android - phonegap 3.3.0 中的本地通知

javascript - 将 requireJS 与 jquery 相关库一起使用(响应式 Iframe)

email - 我可以在我的电子邮件中嵌入 Twitter 源吗?

android - 如何从锁屏开始新 Activity ?

java - 如果使用RelativeLayout则未设置背景图像

java - 比较多个值的算法

java - 使用 Sonar 规则集在本地运行 Maven PMD