0

Hello oh great wizards of all things android. I really need your help. Mostly because my little brain just doesn't know were to start. I am trying to pull data from the internet to make a widget for the home screen. I have the layout built:

<?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>

Got the provider xml bulit:

<?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"
/>

The Manifest works great.

<?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> 

The data it is calling looks something like this when it is called. It basically goes to a website that uses php to random the image:

<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>

But here is were I am stuck. I just don't know where to start at all. The java is so far beyond my little head that I don't know what to do.

package com.dge.myandroid;

import android.appwidget.AppWidgetProvider;

public class mywidget extends AppWidgetProvider {



}

The wiki example just confused me more. I just don't know where to begin. Please help.

cdg
  • 583
  • 1
  • 5
  • 5
  • 2
    Try to pare back your question to the basics. None of those code snippets are relevant, except maybe the HTML info. Search on this site for similar questions; downloading data from the web in Android has definitely been answered before. – Christopher Orr Apr 04 '10 at 18:20
  • I wouldn't post all layout you did since it is not relevant for answering the question properly. – Pablo Santa Cruz Apr 04 '10 at 18:26
  • I wouldn't advise attempt to display HTML content in a widget. Widgets use a cut-down version of Views called RemoteViews. The normal way of showing HTML content in Views, a WebView, isn't supported in RemoteViews. (There may be a way to render HTML to an image, I'd be interested to hear). Anyway it's by the by as the content you include is so simple it would easily be redesigned as RemoteView-compatible content. – Jim Blackler Apr 04 '10 at 18:28

2 Answers2

1

If data is hosted on a WebSite, you can use HttpClient on Android to make the proper request and get your data.

These SO questions might help.

Community
  • 1
  • 1
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • How much would you charge to write the code for me? (Yes, I am that frustrated.) – cdg Apr 04 '10 at 21:23
0

There is code at anddev doing pretty much what you want. The first post is about xml but if you read through there's more, including fetching and parsing HTML.

Jon
  • 611
  • 5
  • 6