因此,我已经在网上搜索了,还没有人遇到我遇到的这个问题.
我正在构建需要推送通知的应用程序.推送通知显示在状态栏中和锁定屏幕上,但仅在应用程序处于活动状态时才会发出声音.我不知道我在想什么.
这是我的代码:
public class PushListenerService extends GcmListenerService { @OverrIDe public voID onMessageReceived(String from, Bundle data) { Log.d("FROM", from); Bundle pushNotification = (Bundle) data.get("notification"); String Title = pushNotification.get("Title").toString(); String body = pushNotification.get("body").toString(); Uri alarmSound = ringtoneManager.getDefaultUri(ringtoneManager.TYPE_NOTIFICATION); notificationmanager notificationmanager = (notificationmanager) getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder notification = new Notification.Builder(this); notification.setContentTitle(Title) .setContentText(body) .setSmallicon(R.drawable.portrait_front) .setSound(alarmSound); notificationmanager.notify(0, notification.build()); }}
任何帮助将不胜感激!
编辑:添加清单以供进一步检查:
<manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="sth.IDapp.androID.privateapp"><application androID:allowBackup="true" androID:label="@string/app_name" androID:icon="@mipmap/ic_launcher" androID:supportsRtl="true" androID:largeHeap="true" androID:theme="@style/Apptheme"> <activity androID:screenorIEntation="portrait" androID:name=".start.StartActivity" androID:theme="@style/Apptheme.HIDeActionbar"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name=".main.MainActivity" androID:screenorIEntation="portrait" androID:label="ID-APPEN" androID:theme="@style/Apptheme.HIDeActionbar"/> <activity androID:name=".styleguIDe.StyleguIDeActivity" androID:screenorIEntation="portrait" androID:label="StyleguIDe" androID:parentActivityname=".main.MainActivity" /> <activity androID:name=".profile.ProfileActivity" androID:screenorIEntation="portrait" androID:label="@string/main_Title" androID:parentActivityname=".main.MainActivity" /> <activity androID:name=".lookups.List.FraudattempsListActivity" androID:screenorIEntation="portrait" androID:label="@string/main_fraud_attempts" androID:parentActivityname=".main.MainActivity" /> <activity androID:name=".lookups.details.FraudattemptsDetailsActivity" androID:screenorIEntation="portrait" androID:label="@string/main_fraud_attempt" androID:parentActivityname=".lookups.List.FraudattempsListActivity" /> <activity androID:name=".lookups.List.EntrIEsListActivity" androID:screenorIEntation="portrait" androID:label="@string/main_entry" androID:parentActivityname=".main.MainActivity" /> <activity androID:name=".profileguIDe.ProfileguIDeActivity" androID:screenorIEntation="portrait" androID:configChanges="keyboardHIDden|orIEntation|screenSize" androID:label="Profil" androID:theme="@style/Apptheme.HIDeActionbar" /> <activity androID:name=".qrcode.QRCodeActivity" androID:screenorIEntation="portrait" androID:label="QR Code" androID:parentActivityname=".main.MainActivity" /> <receiver androID:name="com.Google.androID.gms.gcm.GcmReceiver" androID:exported="true" androID:permission="com.Google.androID.c2dm.permission.SEND" > <intent-filter> <action androID:name="com.Google.androID.c2dm.intent.RECEIVE" /> <category androID:name="sth.IDapp.androID.privateapp" /> </intent-filter> </receiver> <service androID:name=".gcm.PushListenerService" androID:exported="false" > <intent-filter> <action androID:name="com.Google.androID.c2dm.intent.RECEIVE" /> </intent-filter> </service> <service androID:name=".gcm.RegistrationIntentService" androID:exported="false"> <intent-filter> <action androID:name="com.Google.androID.gms.iID.InstanceID"/> </intent-filter> </service> </application> <uses-permission androID:name="androID.permission.INTERNET" /> <uses-permission androID:name="androID.permission.CAMERA" /> <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission androID:name="androID.permission.READ_EXTERNAL_STORAGE" /> <uses-permission androID:name="androID.permission.READ_PHONE_STATE" /> <uses-permission androID:name="androID.permission.WAKE_LOCK" /> <uses-permission androID:name="com.Google.androID.c2dm.permission.RECEIVE" /> <uses-permission androID:name="sth.IDapp.androID.privateapp.permission.RECEIVE" /> <uses-permission androID:name="com.Google.androID.c2dm.permission.SEND" /> <uses-feature androID:name="androID.harDWare.camera" /> <uses-feature androID:name="androID.harDWare.camera.autofocus" /></manifest>
解决方法:
我解决了!
显然问题是我没有从上游发送带有数据有效负载的声音.
这是任何有相同问题的人的代码.
_gcmAPI.SendMessage(request.Uri, request.APIKey, new GCMMessage { to = registrationToken, notification = new notification { body = request.Message, Title = "ID-appen", icon = "@drawable/portrait_front", sound = "default" } });
感谢您的所有帮助!
总结以上是内存溢出为你收集整理的应用未激活时未播放Android通知声音全部内容,希望文章能够帮你解决应用未激活时未播放Android通知声音所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)