gpt4 book ai didi

java - Android Froyo 中未显示通知

转载 作者:行者123 更新时间:2023-12-02 00:01:04 27 4
gpt4 key购买 nike

我正在尝试运行以下命令,该命令是从互联网教程中摘录的:

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 方法链中的某个位置。

当然,启动器绘图是我在那里使用的,因为它是手头的,您将需要为正确的 UI 制作实际的通知图标。这只是为了演示您需要的方法调用。

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

Required notification contents

A Notification object must containthe following:

• A small icon, set by setSmallIcon()

• A title, set by setContentTitle()

• Detail text, set by setContentText()

关于java - Android Froyo 中未显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14864201/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com