应用它没做.....什么的?

时间:2012-07-22 17:09:17

标签: android

我正在修改我正在尝试编写的这个新通知的代码。似乎这样做会更简单,但由于某种原因,它不同意我的看法。它没有给我任何东西。没有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 }

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

1 个答案:

答案 0 :(得分:1)

尝试在通知中设置图标和tickerText:

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

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

来自Notification's documentation

  带有无效图标资源的

通知将不会显示。