0

I'm having requirement where i need to open the class which doesn't extends the activity/class itself is not activity on click of the notification. The code which i have written for the notification forming and also for after clicking on notification.

 public class Services {
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        public void myNotify(Context context) {
            Notification notify = null;
            NotificationManager notif = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

            Notification.Builder builder = new Notification.Builder(getContext());
            // Large icon appears on the left of the notification
            builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
            builder.setTicker("this is ticker text");
            builder.setContentTitle("REX Alert Notification");
            builder.setContentText("You have a new message");
            //adding LED lights to notification
            builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS);
            builder.setLights(0xff00ff00, 300, 100);
            // Hide the notification after its selected
            builder.setAutoCancel(true);


            builder.setOngoing(true);
            builder.build();
            Intent notificationIntent = new Intent(context, AlertView.class);
            PendingIntent pending = PendingIntent.getActivity(getContext(), 0, notificationIntent, 0);
            builder.setContentIntent(pending);
            notify = builder.getNotification();
            notif.notify(0, notify);
        }
    }

Since the class which im passing as the parameter to pendingintent is not a class, so it is not opening. Could you please let me know how to achieve this.

Adding the alertview class:

public static class GenericCallable implements Callable<List<IData>> {
         private final BaseListView    view;

        public GenericCallable(final BaseListView view) {
            this.view = view;
        }

        @Override
        public List<IData> call() throws Exception {
            final IData mData =view.getHeaderData();
            return view.getDataSource().getAll(mData, view.getMaxLength());
        }
    }

    @Override
    public MAUIConfigurationView getSortPopupViewConfig() {
        return ConfigurationManager.getInstance().getView("AlertListSort");
    }
    @Override
    public IDataSource<IData> getDataSourceCallable() {
        return new ArrayDataSource<IData>(new GenericCallable(this));
    }

    @Override
    public int getIntentCode(IData data) {
        return 0xff33;
    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        invalidateList();
    }
}
coders
  • 719
  • 1
  • 11
  • 35

1 Answers1

0

You could use a custom action intent in your pending intent and then do/open whatever you want to do/open in a broadcast receiver :)

see this for a custom action intent: https://stackoverflow.com/a/10922326/3299853

and this for broadcast receiver: https://stackoverflow.com/a/33322662/3299853

Community
  • 1
  • 1
Baniares
  • 525
  • 1
  • 3
  • 9
  • Hello Baniares, Thanks for the reply. But i cannot write my class name in the manifest as suggested in one of the links which you have provided because, the class is not an activity. – coders Oct 26 '15 at 03:31
  • you need to create a broadcast receiver make a pending intent to that broadcast receiver an inside that broadcast receiver open/instantiate your class – Baniares Oct 28 '15 at 16:27