0

我正在修改我正在尝试编写的这个新通知的代码。似乎这样做会更简单,但由于某种原因它不同意我的看法。它没有给我任何东西。没有logcat,模拟器上没有输出。没有。所以这里是修改后的代码:

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 没有给我任何信息它就像应用程序不存在,即使它说它已安装。

以下是一些其他有用的信息:

[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 }

所以它安装它知道它只是不会运行的启动器......

4

1 回答 1

1

尝试为您的通知设置图标和tickerText:

notification.icon = R.drawable.small_notification;
notification.tickerText = "Text that scrolls across the status bar";

好吧,tickerText 是可选的,但图标是必需的。(当我想到它时这是有道理的,因为我们如何在状态栏中看到通知?)

通知的文档

将不会显示具有无效图标资源的通知。

于 2012-07-22T17:17:12.730 回答