【问题标题】:make the notification when pressing a button on android emulator在android模拟器上按下按钮时发出通知
【发布时间】:2011-09-16 09:59:53
【问题描述】:

如果我想让通知在我按下 android 模拟器上的 a 按钮时弹出一条消息“你好”。我应该使用什么代码?再次感谢

【问题讨论】:

  • 好答案,我喜欢。谢谢

标签: java android emulation


【解决方案1】:

这是用户点击按钮时通知用户的示例代码

Button button=(Button)findViewById(R.id.button);
button.setOnClickListener(new OnclickListener(){
    @Override
    public void onClick(View v){

      NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
      Notification notification = new    Notification(R.drawable.image,"Notification",System.currentTimeMillis());
     Intent notificationIntent = new Intent(Currentclass.this,TargetActivity.class);
     PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
     notification.setLatestEventInfo(getApplicationContext(), "Title", "Sub Title",contentIntent);
     notification.flags=Notification.FLAG_AUTO_CANCEL;
     mNotificationManager.notify(143, notification);

  }

});

此代码可能对您有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 2011-04-28
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 2022-01-06
    相关资源
    最近更新 更多