public class PushNotificationsAdapter
extends RecyclerView.Adapter<PushNotificationsAdapter.ViewHolder>{
ArrayList<PushNotification> pushNotifications = new ArrayList<>();
public PushNotificationsAdapter() {
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View itemView = inflater.inflate(R.layout.item_list_notification, parent, false);
return new ViewHolder(itemView);
}
public void onButtonClick(View view)
{
Uri uri = Uri.parse("http://www.ciberesquina.una.edu.ve/evaluacion/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
Чтобы реализовывать один Intent
внутри Пус Нотификатион он осуществляется посредством одного PendingIntent
, я добавляю тебя пример:
public static void creaNotificacion(long when, String notificationTitle,
String notificationContent, String notificationUrl, Context ctx) {
try {
Intent notificationIntent;
Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(),
R.drawable.ic_launcher);
int smalIcon = R.drawable.ic_launcher;
/* Valida la url y crea un Intent */
if (!"".equals(notificationUrl)) {
notificationIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(notificationUrl));
} else {
notificationIntent = new Intent();
}
/* Crea PendingIntent */
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager notificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
/* Construye la notificacion */
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
ctx).setWhen(when).setContentText(notificationContent)
.setContentTitle(notificationTitle).setSmallIcon(smalIcon)
.setAutoCancel(true).setTicker(notificationTitle)
.setLargeIcon(largeIcon)
.setContentIntent(pendingIntent);
notificationManager.notify((int) when, notificationBuilder.build());
} catch (Exception e) {
Log.e("Notificacion", "createNotification::" + e.getMessage());
}
}
из этой формы ты призываешь mГ©todo создавать ее notificaciГіn:
creaNotificacion(0,"Notificación Android!","Como llamar a una alerta o notificación para el usuario en la aplicación de Android?", "http://es.stackoverflow.com", getApplicationContext());
, открыв ее notificaciГіn с бруска извещений и ты можешь выполнять одну acciГіn посредством PendingIntent, в этом примере он откроет url.
Как дополнение, в которое он поместил @Elenasys, также могут добавлять кнопки действия к извещению с api 4.1. Чтобы видеть основные концепции относительно извещения, консультируй документацию android.
Intent notificationIntent;
/* Valida la url y crea un Intent */
if (!"".equals(notificationUrl)) {
notificationIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.ciberesquina.una.edu.ve/evaluacion/"));
} else {
notificationIntent = new Intent();
}
/* Crea PendingIntent */
PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(),
R.drawable.ic_launcher);
int smalIcon = R.drawable.ic_launcher;
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(smalIcon)
// añadimos los botones que queramos, cada uno con su pending intent
.addAction(R.drawable.ic_web, "Ir a", pendingIntent )
.setContentTitle("Nueva notificación")
.setContentText("Ejemplo notificación con botón")
.setLargeIcon(largeIcon)
.build();
notificationManager.notify((int) when, notification);