I am tinkering with the code for this new notification I’m trying to write. Seems like it would be more simple to do but for some reason its not agreeing with me. Its not giving me anything. No logcat, no output on the emulator. Nothing. So here is the modified code:
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews;
public class kickStart extends Activity {
NotificationManager nm;
Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.note);
contentView.setImageViewResource(R.id.icon, R.drawable.ic_launcher);
contentView.setTextViewText(R.id.title, "Custom notification");
contentView.setTextViewText(R.id.text, "This is a custom layout");
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
nm.notify(R.id.layout, notification);
}
}
Logcat is not giving me any info Its like the app don’t exist even though its saying it installed.
Here is some other useful info:
[2012-07-22 12:57:21 - this1] Android Launch!
[2012-07-22 12:57:21 - this1] adb is running normally.
[2012-07-22 12:57:21 - this1] Performing com.example.this1.kickStart activity launch
[2012-07-22 12:57:21 - this1] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'test'
[2012-07-22 12:57:21 - this1] Uploading this1.apk onto device 'emulator-5554'
[2012-07-22 12:57:23 - this1] Installing this1.apk...
[2012-07-22 12:57:31 - this1] Success!
[2012-07-22 12:57:32 - this1] Starting activity com.example.this1.kickStart on device emulator-5554
[2012-07-22 12:57:33 - this1] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.this1/.kickStart }
So it installs it knows of a launcher it just wont run…
Try setting an icon and tickerText to your notification:
Well, the tickerText is optional, but the icon is required. (Which makes sense when I think about it because how else would we see the notification in the status bar?)
From Notification’s documentation: