通知适用于模拟器,但不适用于真实设备

时间:2018-04-02 07:04:09

标签: android

我使用以下代码向用户发送通知声音。这在模拟器上工作得很好,但在真实设备上却不行。真实设备只是保持沉默。

NotificationManager notificationManager = (NotificationManager) reactContext.getSystemService(Context.NOTIFICATION_SERVICE);

Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getReactApplicationContext())
        .setContentTitle("foo")
    .setContentText("bar")
        .setSound(soundUri, AudioManager.STREAM_NOTIFICATION)
        .setAutoCancel(true);

notificationManager.notify(0, mBuilder.build());

以下是我添加的应用权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.BIND_CARRIER_SERVICES" />
<uses-permission android:name="android.permission.BIND_MIDI_DEVICE_SERVICE" />
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND" />
<uses-permission android:name="android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND" />

仿真器目标是API v 23上的Androd 6.0

它还能做什么?感谢

0 个答案:

没有答案