Created
September 8, 2015 02:13
-
-
Save punchdrunker/e5da74b8948abc8016c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.rssreader; | |
import android.content.Context; | |
import android.util.Log; | |
import com.squareup.okhttp.OkHttpClient; | |
import com.squareup.okhttp.Request; | |
import com.squareup.okhttp.Response; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Hideyuki.Kikuma on 15/09/02. | |
*/ | |
public class FeedFetcher { | |
private Context context; | |
private static final String RSS_URL = "http://news.yahoo.co.jp/pickup/computer/rss.xml"; | |
public FeedFetcher(Context context) { | |
this.context = context; | |
} | |
/** | |
* 記事一覧を取得する | |
* | |
* @return 記事リスト | |
*/ | |
public List<FeedItem> fetch() { | |
Request request = new Request.Builder() | |
.url(RSS_URL) | |
.get() | |
.build(); | |
OkHttpClient client = new OkHttpClient(); | |
try { | |
Response response = client.newCall(request).execute(); | |
String result = response.body().string(); | |
Log.d("FeedFetcher", result); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
List<FeedItem> result = new ArrayList<>(); | |
result.add(new FeedItem("最初の大ニュースです!", "これはすごい", "スクープ", "2015/9/1")); | |
result.add(new FeedItem("次の大ニュースです!", "これはすごいこれはすごい", "スクープ", "2015/9/1")); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
32行目以降が、実際にネットワーク接続する処理になります