Rss feed item click to open in app instead of browser« Back to Previous Page

So I have my browser activity ready, however I'm struggling to get the code working to open the link from my rss feed to open in that, it just goes to a blank page. I have tried numerous things but nothing is working. So I have ended up going back to standard code as used in this tutorial. I am using the engadget feed as an example to see if i could get it working. Here is my listlistener activity

public class ListListener implements OnItemClickListener { // List item's reference
List<RssItem> listItems;
// Calling activity reference
Activity activity;

public ListListener(List<RssItem> aListItems, Activity anActivity) {
listItems = aListItems;
activity = anActivity;
}

/**
* Start a browser with url from the rss item.
*/
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(listItems.get(pos).getLink()));

activity.startActivity(i);

}

}
and here is my engadgetfeed activity

public class EngadgetFeed extends Activity {

private EngadgetFeed local;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_engadget_feed);
// Set reference to this activity
local = this;

GetRSSDataTask task = new GetRSSDataTask();

// Start download RSS task
task.execute("http://www.engadget.com/rss.xml");

// Debug the thread name
Log.d("Engadget", Thread.currentThread().getName());
}

private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem> > {
@Override
protected List<RssItem> doInBackground(String... urls) {

// Debug the task thread name
Log.d("Engadget", Thread.currentThread().getName());

try {
// Create RSS reader
RssReader rssReader = new RssReader(urls[0]);

// Parse RSS, get items
return rssReader.getItems();

} catch (Exception e) {
Log.e("Engadget", e.getMessage());
}

return null;
}

@Override
protected void onPostExecute(List<RssItem> result) {

// Get a ListVi ew from main view
ListView endgadgetfeed = (ListView) findViewById(R.id.listMainView);

// Create a list adapter
ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(local,R.layout.simple_list_item_1, result);
// Set list adapter for the ListView
endgadgetfeed.setAdapter(adapter);

// Set list view item click listener
endgadgetfeed.setOnItemClickListener(new ListListener(result, local));
}
}


}
any help would be appreciated
Posted by James Graham (Questions:3, Answers:1)
Asked on September 28, 2013 2:30 pm
Category: Android
0

nice

Posted by Anuj Dhiman (Questions:0, Answers:1)
Answered On November 3, 2015 1:55 pm #
1

You might find the code of the ITCutiesApp interesting – https://github.com/itcuties/ITCutiesApp-1.0. It has all the features you might need in your app like opening article in the app. They remove all the JavaScripts and styles in the fly when opening the article which I found useful.

Posted by charlie (Questions:9, Answers:15)
Answered On September 29, 2013 11:27 am #
2

I have already sorted this out. What I wanted was it to open within my app, I have a built in browser which I like to use to keep the UX smoother. My app is based on what you said. The code I changed was in the listlistener activity.

I changed it to


public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
Uri uri;
String stringuri;
stringuri = (Uri.parse(listItems.get(pos).getLink())).toString();

Intent i = new Intent(activity, Browser2.class);
i.putExtra(EXTRA_MESSAGE, stringuri);

activity.startActivity(i);

}
Posted by James Graham (Questions:3, Answers:1)
Answered On September 29, 2013 10:40 am #
0

The code you have shown above works just fine. The link opens in the android browser.
Try again, take the code from this tutorial – http://www.itcuties.com/android/android-asynctask-rss-reader/, change the RSS URL and it will work. Build your app based on that example.

Posted by charlie (Questions:9, Answers:15)
Answered On September 29, 2013 8:31 am #
No account?



It's FREE!

Like what you have found?


... and keep us going