安卓通知

发布于 2024-11-26 20:49:49 字数 1028 浏览 0 评论 0原文

我的要求是需要在上传可用时显示通知。Each &每次进入新的 Activity 时,都会检查上传是否可用。(上传的意思是:如果 android 数据库中发生任何更改,则表明需要上传到实际的 sql server 数据库)。

查看我的代码:

   uploadSize = new UploadActivity().getUploadTable();
    if(uploadSize > 0){
        Button button = (Button) findViewById(R.id.u);
        button.setBackgroundColor(Color.RED);

        long whenTo = System.currentTimeMillis();
        Notification n = new Notification(R.drawable.icon, "", whenTo);
        n.tickerText = "TV Spored ++";

        String contentTitle = "I am expanded title";
        String contentText = "I am expanded text";
        Intent intent = new Intent(this, NotificationReceiver.class);
        // Put additional stuff into the created intent
        PendingIntent contentIntent = PendingIntent.getActivity(this, 1, intent, 1);
        n.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
    }

从我的代码来看,

  1. 它没有显示在栏的顶部。
  2. 有没有什么好的解决办法可以上传一下。

请帮助我..

提前致谢。

有没有

My requirement is need to display notification,when upload is available.Each & every time go to new Activity, It check Upload is available.(Upload mean : IF there any changes happened in android db, then it indicate need to upload to actual sql server db).

See my code :

   uploadSize = new UploadActivity().getUploadTable();
    if(uploadSize > 0){
        Button button = (Button) findViewById(R.id.u);
        button.setBackgroundColor(Color.RED);

        long whenTo = System.currentTimeMillis();
        Notification n = new Notification(R.drawable.icon, "", whenTo);
        n.tickerText = "TV Spored ++";

        String contentTitle = "I am expanded title";
        String contentText = "I am expanded text";
        Intent intent = new Intent(this, NotificationReceiver.class);
        // Put additional stuff into the created intent
        PendingIntent contentIntent = PendingIntent.getActivity(this, 1, intent, 1);
        n.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
    }

From the my code ,

  1. it didn't show the on the top of the bar.
  2. Is there any good solution is available for upload.

Please help me..

Thanks in advance.

Is there any

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

じ违心 2024-12-03 20:49:49

显示通知调用此方法

private void triggerNotification(String s) {
        CharSequence title = "Hello";
        CharSequence message = s;
        NotificationManager notificationManager;
        notificationManager = (NotificationManager) context
                .getSystemService("notification");
        Notification notification;
                notification = new Notification(R.drawable.icon, "", whenTo);

        // Intent notificationIntent = new
        // Intent(android.content.Intent.ACTION_VIEW, null, context,
        // NotificationBariconExmp.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                null, 0);

        notification.setLatestEventInfo(context, title, message, pendingIntent);
        notificationManager.notify(1010, notification);

    }

To show Notification Call this method

private void triggerNotification(String s) {
        CharSequence title = "Hello";
        CharSequence message = s;
        NotificationManager notificationManager;
        notificationManager = (NotificationManager) context
                .getSystemService("notification");
        Notification notification;
                notification = new Notification(R.drawable.icon, "", whenTo);

        // Intent notificationIntent = new
        // Intent(android.content.Intent.ACTION_VIEW, null, context,
        // NotificationBariconExmp.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                null, 0);

        notification.setLatestEventInfo(context, title, message, pendingIntent);
        notificationManager.notify(1010, notification);

    }
謸气贵蔟 2024-12-03 20:49:49

您需要使用 NotificationManager

您可以将此作为指南:创建状态栏通知

You'll need to use the NotificationManager.

You can use this as a guide: Creating Status Bar Notifications

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文