Example usage for android.content Intent filterEquals

List of usage examples for android.content Intent filterEquals

Introduction

In this page you can find the example usage for android.content Intent filterEquals.

Prototype

public boolean filterEquals(Intent other) 

Source Link

Document

Determine if two intents are the same for the purposes of intent resolution (filtering).

Usage

From source file:digital.dispatch.TaxiLimoNewUI.GCM.CommonUtilities.java

public static BroadcastReceiver getGenericReceiver(final Context ctx, final boolean isTrackDetail) {
    final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
        @Override//from  w w w  .j a  v  a2s .  c o m
        public void onReceive(Context context, Intent intent) {
            if (intent.filterEquals(new Intent(gcmType.message.toString()))) {
                // get gcm notification ID to remove notification once read by user
                String newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
                final int gcmID = intent.getIntExtra(GCM_ID, -1);

                AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
                builder.setTitle(R.string.gcm);
                builder.setMessage(newMessage);
                builder.setCancelable(false);

                // Create the AlertDialog object and return it
                builder.create();

                // clear late trip notification list once displayed
                SharedPreferences sharedPref = ctx.getSharedPreferences("mobile_booker", 0);
                SharedPreferences.Editor prefEditor = sharedPref.edit();
                final String lateID = sharedPref.getString(LATE_TRIP_TRID, "");

                if (!lateID.equalsIgnoreCase("")) {
                    DaoManager daoManager = DaoManager.getInstance(ctx);
                    DBBookingDao bookingDao = daoManager.getDBBookingDao(DaoManager.TYPE_WRITE);
                    final DBBooking dbBook = bookingDao.queryBuilder().where(Properties.Taxi_ride_id.eq(lateID))
                            .list().get(0);

                    builder.setPositiveButton(R.string.late_trip_wait, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            removeNotification(gcmID, ctx);

                        }
                    }).setNegativeButton(R.string.late_trip_no_wait, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            new CancelJobTask(ctx, dbBook).execute();
                            removeNotification(gcmID, ctx);
                        }
                    });

                    prefEditor.putString(LATE_TRIP_TRID, "");
                    prefEditor.commit();
                } else {
                    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            removeNotification(gcmID, ctx);
                            if (isTrackDetail)
                                ((TrackDetailActivity) ctx).startRecallJobTask();
                            if (ctx instanceof MainActivity) {
                                if (((MainActivity) ctx).trackFragment.isAdded())
                                    ((MainActivity) ctx).trackFragment.startRecallJobTask();
                            }
                        }
                    });
                }
                try {
                    builder.create().show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    };

    return mHandleMessageReceiver;
}