Android中的通知有问题吗?
这是我在完成第一个活动中的任务后调用的通知类中的代码 但是我在获取当前应用程序的通知时遇到了问题 我想将通知显示为对话框Android中的通知有问题吗?,android,android-notifications,Android,Android Notifications,这是我在完成第一个活动中的任务后调用的通知类中的代码 但是我在获取当前应用程序的通知时遇到了问题 我想将通知显示为对话框 "R.layout.main" 包含带有“确定”按钮的对话框 public class Notif extends Activity implements View.OnClickListener { private Button Button01; private NotificationManager mManager; private static
"R.layout.main"
包含带有“确定”按钮的对话框
public class Notif extends Activity implements View.OnClickListener {
private Button Button01;
private NotificationManager mManager;
private static final int APP_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.Button01 = (Button) this.findViewById( R.id.Button1);
this.Button01.setOnClickListener(this);
mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this,Notif.class);
Notification notification = new Notification(R.drawable.icon,
"Notify", System.currentTimeMillis());
notification.setLatestEventInfo(Notif.this,"App Name","Description of the notification",PendingIntent.getActivity(this.getBaseContext(), 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT));
mManager.notify(APP_ID, notification);
}
}
1) 为什么要使用View.OnClickListener的实现来处理按钮侦听器
到目前为止,我看到的标准方法是:
Button01.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Your code
}
});
2) 通知是通过屏幕顶部的Android状态面板通知用户的方式。我不明白你想用通知和对话框做什么-决定你想要哪一个
如果您确实想使用通知,那么这就是我的onStop()
方法中的内容(基本上就是您从Android指南中获得的):
这是通过mNotificationManager=(NotificationManager)getSystemService(通知服务)实现的代码>已在onCreate()中完成
真的不知道你想做什么 谢谢你给我的时间…实际上我已经创建了活动,其中我有一个最大限制的进度条..所以在进度条达到最大值后,我想显示消息框。它必须在任何当前应用程序上看到..这就是我试图创建对话框作为通知..请帮我实现它…你想创建一个通知和弹出框?我真的认为你应该坚持创建一个通知,它们是很难错过的,应该可以通知用户(这就是它们的目的)。然后,如果需要从活动中显示更多信息,可以在活动中弹出一个对话框。我认为您不应该尝试从一个未聚焦的活动中同时执行通知和对话框(理想情况下,您也应该从一个服务中执行通知,我认为这是另一回事)。@是的,您是对的,但我可以在屏幕中间显示消息窗口作为通知,我想在这个消息框上加上按钮……请在progressbar完成后实现一个对话框,看看会发生什么?很可能它不会触发,但耸耸肩。是的,我在完成进度条后创建了对话框,但我的对话框仅在我的应用程序中看到…我必须在当前运行的应用程序上看到该对话框…那么,我该怎么办???
Notification notification = new Notification(R.drawable.icon, "App Name", System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, ClassToStart.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(), "App Name", "Press here to resume", contentIntent);
mNotificationManager.notify(1, notification);