尝试通知

时间:2014-02-20 16:53:27

标签: java android android-intent

我正在尝试通过我的IntentService显示通知。

但没有显示: - (((

public class CreditcheckService extends IntentService {
    AlertDialog dialog;
    public CreditcheckService() {
        super("CreditcheckService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle("My notification")
            .setContentText("Hello World!");
        NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(999, mBuilder.build());
}

1 个答案:

答案 0 :(得分:2)

我添加了以下内容:

    mBuilder.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0));

它有效......