通知不起作用(htc 野火)

发布于 2024-12-06 22:00:34 字数 1451 浏览 1 评论 0原文

我正在尝试使用通知管理器播放声音,并闪烁 Android 手机的背光。我使用了以下代码。所有必需的权限都在清单文件中。但我不确定为什么这不会在模拟器或设备(htc野火)中发出任何通知。如果您知道任何可行的解决方案,请告诉我

XYNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        int NOTFICATION_ID = 1331;
        Notification notifyDetails = new Notification();
        notifyDetails.icon = R.drawable.icon12;
        notifyDetails.tickerText = "Message Received!!!";
        notifyDetails.when = System.currentTimeMillis();

        notifyDetails.vibrate = new long[] {0,1000,1000,1000,1000,1000,1000,1000}; //vibrate;

        Intent notifyIntent = new Intent(this, XYReceiverAppActivity.class);

        PendingIntent pIntent = PendingIntent.getActivity(this, 0,notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

        CharSequence contentTitle = "XYs Notification";
        CharSequence contentText = "Get back to XY HOME screen by clicking me";


        notifyDetails.setLatestEventInfo(this, contentTitle, contentText, pIntent);

        Uri xysound = Uri.parse("android.resource://" + getPackageName() +"/"+ "soundxy");

        notifyDetails.ledARGB = Color.BLUE;
        notifyDetails.ledOnMS = 10000;
        notifyDetails.ledOffMS = 1000;
        notifyDetails.flags |= Notification.FLAG_SHOW_LIGHTS;
        notifyDetails.sound =  xysound;



        XYNotificationManager.notify(NOTFICATION_ID, notifyDetails);

该设备没有振动,也没有任何声音警报。 LED灯是一样的。我如何发送通知?

I am trying to play a sound, and flash the backlight of android phone using notification manager. I have used the following code. All the required permissions are there in the manifest file. But I am not sure why this is not giving any notification in emulator or in the device (htc wildfire). If you know any feasible solution please let me know

XYNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        int NOTFICATION_ID = 1331;
        Notification notifyDetails = new Notification();
        notifyDetails.icon = R.drawable.icon12;
        notifyDetails.tickerText = "Message Received!!!";
        notifyDetails.when = System.currentTimeMillis();

        notifyDetails.vibrate = new long[] {0,1000,1000,1000,1000,1000,1000,1000}; //vibrate;

        Intent notifyIntent = new Intent(this, XYReceiverAppActivity.class);

        PendingIntent pIntent = PendingIntent.getActivity(this, 0,notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

        CharSequence contentTitle = "XYs Notification";
        CharSequence contentText = "Get back to XY HOME screen by clicking me";


        notifyDetails.setLatestEventInfo(this, contentTitle, contentText, pIntent);

        Uri xysound = Uri.parse("android.resource://" + getPackageName() +"/"+ "soundxy");

        notifyDetails.ledARGB = Color.BLUE;
        notifyDetails.ledOnMS = 10000;
        notifyDetails.ledOffMS = 1000;
        notifyDetails.flags |= Notification.FLAG_SHOW_LIGHTS;
        notifyDetails.sound =  xysound;



        XYNotificationManager.notify(NOTFICATION_ID, notifyDetails);

The device is not vibrating neither is there any sound alert. LED light is same. how do I send the notification?

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

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

发布评论

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

评论(1

她比我温柔 2024-12-13 22:00:34

这是我在我的一个程序中使用的代码,它总是有效......

        int icon = R.drawable.alerte;
        CharSequence tickerText = getString(R.string.lieuproche);
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
        Intent intent = new Intent(getApplicationContext(),
                ActivityToLaunch.class);

        notification.setLatestEventInfo(
                MainActivity.this,
                "title",
                "action", PendingIntent.getActivity(
                        this.getBaseContext(), 0, intent,
                        PendingIntent.FLAG_CANCEL_CURRENT));
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notificationManager.notify(0, notification);

Here is a code I use in one of my programs, it always worked...

        int icon = R.drawable.alerte;
        CharSequence tickerText = getString(R.string.lieuproche);
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
        Intent intent = new Intent(getApplicationContext(),
                ActivityToLaunch.class);

        notification.setLatestEventInfo(
                MainActivity.this,
                "title",
                "action", PendingIntent.getActivity(
                        this.getBaseContext(), 0, intent,
                        PendingIntent.FLAG_CANCEL_CURRENT));
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notificationManager.notify(0, notification);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文