RSS Reader mit Benachrichtung

  • Antworten:3
JulianTH
  • Forum-Beiträge: 12

04.04.2013, 19:11:29 via Website

Hallo,

ich weiß, dass es bereits 1-2 Threads dazu gibt...
aber ich bin da doch noch ein bisschen planlos.

Ich möchte gerne meinen RSS Reader erweitern mit Benachrichtungen, falls es einen neuen RSS Feed gibt.

Wie man eine Notifications erstellt leuchtet mir anhand dieses Codes ein:
1public class NotificationActivity extends Activity {
2 @Override
3 public void onCreate(Bundle savedInstanceState) {
4 super.onCreate(savedInstanceState);
5 setContentView(R.layout.main);
6 }
7
8 public void createNotification(View view) {
9 // Prepare intent which is triggered if the
10 // notification is selected
11 Intent intent = new Intent(this, NotificationReceiverActivity.class);
12 PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
13
14 // Build notification
15 // Actions are just fake
16 Notification noti = new Notification.Builder(this)
17 .setContentTitle("New mail from " + "test@gmail.com")
18 .setContentText("Subject").setSmallIcon(R.drawable.icon)
19 .setContentIntent(pIntent)
20 .addAction(R.drawable.icon, "Call", pIntent)
21 .addAction(R.drawable.icon, "More", pIntent)
22 .addAction(R.drawable.icon, "And more", pIntent).build();
23 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
24 // Hide the notification after its selected
25 noti.flags |= Notification.FLAG_AUTO_CANCEL;
26
27 notificationManager.notify(0, noti);
28
29 }
30}

Ab dann bin ich allerdings ratlos... . Mir fehlt quasi der Schritt "Neuer Feed ---> Notification"

Vielleicht kann mir jemand helfen?

Lg

Thomas Schlagkamp

Antworten
Thomas Schlagkamp
  • Forum-Beiträge: 14

05.04.2013, 15:52:49 via Website

Hi. Das Gleiche Probelm habe ich auch. Den entsprechenden intervall habe ich laufen, auch die Feeds werden abgerufen. Es fehlt der schritt des Speicherns und vergleichens. Hier mein Ansatz.
Habe auch noch einen zweiten Ansatz aber da komme ich mal so gar nicht weiter.
https://www.nextpit.de/de/android/forum/thread/549458/Rss-feed-mit-Statusbar-Notification

Leider bisher auch ohne Erfolg



1public int onStartCommand(Intent intent, int flags, int startId) {
2 Log.v("Service", System.currentTimeMillis()
3 + ": Service gestartet.");
4
5 // Ab hier werden die Feeds aufgerufen
6
7 try {
8 URL rssUrl = new URL("http://www.abc.de");
9 SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
10 SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
11 XMLReader myXMLReader = mySAXParser.getXMLReader();
12 RSSHandler myRSSHandler = new RSSHandler();
13 myXMLReader.setContentHandler(myRSSHandler);
14 InputSource myInputSource = new InputSource(rssUrl.openStream());
15 myXMLReader.parse(myInputSource);
16
17 myRssFeed = myRSSHandler.getFeed();
18 } catch (MalformedURLException e) {
19 e.printStackTrace();
20 } catch (ParserConfigurationException e) {
21 e.printStackTrace();
22 } catch (SAXException e) {
23 e.printStackTrace();
24 } catch (IOException e) {
25 e.printStackTrace();
26 }
27
28
29
30
31
32
33
34
35 if (title.equals(sharedpreference.getString("alteuberschrift", "keine Uberschirft vorhanden"){
36
37
38 Intent intent1 = new Intent(context, NotificationActivity.class);
39 startActivity(intent1);
40
41
42
43
44
45
46
47
48
49
50 }
51
52 //
53 // selbst stoppen.
54 stopSelf();

Antworten
Enrico
  • Forum-Beiträge: 33

06.04.2013, 15:35:31 via App

man erstellt eine vaiable vom typ string, nenndn wir sie ueberschrift.
dann brauch man eine shared preference, in die man die alte ueberschrift speichert. und dann prüft man die variable ueberschrift auf übereinstimmigkeit mit der überschrift aus der shared preference. sind beide gleich ist nix neues vorhanden, sind sie unterschiedlich, dann wird der anwenxer benacgrichtigt und die variabld ueberschrift in der shared preference gespeichert.
code siehe oben.

— geändert am 06.04.2013, 15:37:28

Antworten
Thomas Schlagkamp
  • Forum-Beiträge: 14

06.04.2013, 19:09:29 via Website

Genau da liegt der hund begraben. Jeglicher versuch meinerseits die Überschrift rauszufiltern und zu speichern ist bisher fehlgeschlagen

Antworten