小编Bas*_*nth的帖子

通知声音,振动和LED不起作用

我正在尝试在我的应用程序中为Notificaitons设置自定义声音,振动和LED颜色 - 但它不起作用.设置标题,图标,颜色等所有其他工作正常.我在Stackoverflow中尝试了很多解决方案,但它们也没有用,所以我问了一个问题.

这是我的通知代码 -

    Intent resultIntent = new Intent(this, ActivityB.class);
    Bundle b = new Bundle();
    //Some bundle related Code
    resultIntent.putExtra("bundle",b);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(new Intent(this, ActivityA.class));
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);

    android.support.v7.app.NotificationCompat.Builder builder = new android.support.v7.app.NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_small_logo);
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_logo_large));
    builder.setContentTitle(notification.getTitle());
    builder.setContentText(notification.getBody());
    builder.setColor(Color.parseColor("#FFFFFF"));
    builder.setStyle(new NotificationCompat.BigTextStyle());
    builder.setVibrate(new long[] { 1000, 100, 1000, 100, 1000 });
    builder.setLights(Color.YELLOW, 3000, 3000);
    builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notif1));
    builder.setAutoCancel(true);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(1, builder.build());
Run Code Online (Sandbox Code Playgroud)

我也加入了振动许可.在运行Lollipop和Marshmallow的2部手机上进行了测试.

编辑1:

共享我的应用程序使用的所有权限 -

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" …
Run Code Online (Sandbox Code Playgroud)

notifications android push-notification

14
推荐指数
1
解决办法
1290
查看次数

标签 统计

android ×1

notifications ×1

push-notification ×1