Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Froyo中未显示通知_Java_Android_Android 2.2 Froyo - Fatal编程技术网

Java Android Froyo中未显示通知

Java Android Froyo中未显示通知,java,android,android-2.2-froyo,Java,Android,Android 2.2 Froyo,我正在尝试运行以下内容,这些内容摘自互联网教程: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // Prepare intent which is triggered if the // notification is selected Intent homeIntent = new Intent(

我正在尝试运行以下内容,这些内容摘自互联网教程:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Prepare intent which is triggered if the
    // notification is selected

    Intent homeIntent = new Intent(Intent.ACTION_MAIN);
    homeIntent.addCategory(Intent.CATEGORY_HOME);
    //Intent intent = new Intent(this, ReceiveAndGoHome.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, homeIntent, 0);


    // Build notification
    // Actions are just fake
    Notification noti = new NotificationCompat.Builder(this)
    .setContentTitle("Fraz Go Home!!!")
            .setContentTitle("Fraz Go Home!!!")
            .setContentText("Fraz Go Home!!!")
            .setContentIntent(pIntent)
            .addAction(R.drawable.ic_launcher, "Call", pIntent)
            .addAction(R.drawable.ic_launcher, "More", pIntent)
            .addAction(R.drawable.ic_launcher, "And more", pIntent).build();


    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // Hide the notification after its selected
    noti.flags |= Notification.FLAG_AUTO_CANCEL;


    notificationManager.notify(25, noti); 

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}
}

当我在froyo AVD中运行上述操作时,我根本看不到出现通知-我是否遗漏了一些明显的内容?

您忘记设置小图标了。添加以下内容:

.setSmallIcon (R.drawable.ic_launcher)
NotificationCompat.Builder
方法链中的某个位置

当然,launcher drawable是我在那里使用的,因为它在手上,你需要为一个合适的UI制作实际的通知图标。这只是演示您需要的方法调用

概述了通知显示所需的内容:

所需通知内容

通知对象必须包含 以下是:

•一个小图标,由setSmallIcon()设置

•标题,由setContentTitle()设置

•详细文本,由setContentText()设置


你忘记设置小图标了。添加以下内容:

.setSmallIcon (R.drawable.ic_launcher)
NotificationCompat.Builder
方法链中的某个位置

当然,launcher drawable是我在那里使用的,因为它在手上,你需要为一个合适的UI制作实际的通知图标。这只是演示您需要的方法调用

概述了通知显示所需的内容:

所需通知内容

通知对象必须包含 以下是:

•一个小图标,由setSmallIcon()设置

•标题,由setContentTitle()设置

•详细文本,由setContentText()设置