I’m following this guide but I’ve remade it a bit;
removed the first activity with all the email and name stuff. Basicly, what Ive done is:
an app with a button and a textview and when you press the button the regId pops up. So far so good, but when it comes to receiving the push itself there’s no popup, no wake lock or anything, just a simple row in the “notification center” (dont really know what its called on android). heres the code:
private static void generateNotification(Context context, String message)
{
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MainActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Errors:
Notification notification = new Notification(icon, message, when);
The constructor Notification(int, charSequence, long) is deprecated
notification.setLatestEventInfo(context, title, message, intent);
The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) from the type Notification is deprecated
(the logCat comes out clean from errors)
when I open the declaration it says “The JAR file has no source attachment”.
I’ve tried to add sources and googleing. but whatever i do it says
the source attachment does not contain the source for the file Notification.class
I believe that my problem with getting the message in the push is because of this. any ideas on how to fix it?
PS. I’m new to all this, please let me know if you need more of the code AND do tell me if I’m on the wrong track here!:)
This has nothing to do with your warning. The warning just says, that the method that you are using is deprecated since API level 11. For newer APIs you can(but you don’t have to, it’s just recommended) use Notification.Builder:
Edit:
checking for current API:
Edit2:
You can use the Notification.Builder on lower APIs if you use the support lib.