Android Notificaciones

Páginas: 13 (3044 palabras) Publicado: 9 de julio de 2012
V EJERCICIOS
1. Tomando como base la aplicación del servicio de noticias desarrolladas en una práctica
anterior, incluya acciones que permitan recibir y mostrar notificaciones cuando nuevas noticias
sea emitidas por el proveedor del servicio.
Earthquake.java
package com.paad.earthquake;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
importandroid.app.NotificationManager;
import android.content.*;
import android.content.res.Resources;
import android.database.Cursor;
import android.location.Location;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
importandroid.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class Earthquake extends Activity {
static final int QUAKE_DIALOG = 1;
static final int MENU_UPDATE = Menu.FIRST;
static final int MENU_PREFERENCES = Menu.FIRST+1;
static final intSHOW_PREFERENCES = 1;
static final int MENU_EARTHQUAKE_MAP = Menu.FIRST+2;
ListView earthquakeListView;
ArrayList earthquakes = new ArrayList();
ArrayAdapter aa;
Quake selectedQuake;
EarthquakeReceiver receiver;

NotificationManager notificationManager;
// Preference values
int minimumMagnitude = 0;
boolean autoUpdate = false;
int updateFreq = 0;
@Override
public void onCreate(Bundleicicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
earthquakeListView = (ListView)this.findViewById(R.id.earthquakeListView);
earthquakeListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView _av, View _v, int _index, long _id) {
selectedQuake = earthquakes.get(_index);
showDialog(QUAKE_DIALOG);
}
});
int layoutID =android.R.layout.simple_list_item_1;
aa = new ArrayAdapter(this, layoutID , earthquakes);
earthquakeListView.setAdapter(aa);
loadQuakesFromProvider();
updateFromPreferences();
refreshEarthquakes();
notificationManager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
}
/** Refresh data from the earthquake feed using the Service*/
private void refreshEarthquakes() {
startService(newIntent(this, EarthquakeService.class));
}
/** Add a new quake to the ArrayList */
private void addQuakeToArray(Quake _quake) {
if (_quake.getMagnitude() > minimumMagnitude) {
// Add the new quake to our list of earthquakes.
earthquakes.add(_quake);
// Notify the array adapter of a change.
aa.notifyDataSetChanged();
}
}
/** Retrieve the Quakes from provider and populate the ArrayList */private void loadQuakesFromProvider() {
// Clear the existing earthquake array

earthquakes.clear();
ContentResolver cr = getContentResolver();
// Return all the saved earthquakes
Cursor c = cr.query(EarthquakeProvider.CONTENT_URI, null, null, null, null);
if (c.moveToFirst())
{
do {
// Extract the quake details.
Long datems = c.getLong(EarthquakeProvider.DATE_COLUMN);
String details =c.getString(EarthquakeProvider.DETAILS_COLUMN);
Float lat = c.getFloat(EarthquakeProvider.LATITUDE_COLUMN);
Float lng = c.getFloat(EarthquakeProvider.LONGITUDE_COLUMN);
Double mag = c.getDouble(EarthquakeProvider.MAGNITUDE_COLUMN);
String link = c.getString(EarthquakeProvider.LINK_COLUMN);
Location location = new Location("dummy");
location.setLongitude(lng);
location.setLatitude(lat);Date date = new Date(datems);
Quake q = new Quake(date, details, location, mag, link);
addQuakeToArray(q);
} while(c.moveToNext());
}
c.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, MENU_UPDATE, Menu.NONE, R.string.menu_update);
menu.add(0, MENU_PREFERENCES, Menu.NONE, R.string.menu_preferences);
// menu.add(0,...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • CAMBIAR LOS TONOS DE LLAMADA, NOTIFICACIONES Y ALARMAS EN ANDROID
  • Dialogo y notificaciones en android
  • Notificaciones
  • notificaciones
  • notificaciones
  • Las Notificaciones
  • Notificaciones
  • notificaciones

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS