如何设置通知,在Android的自定义音效自定义、音效、如何设置、通知

由网友(墨染的泪)分享简介:我复制的MP3(kalimba.mp3)文件到原始文件夹中的资源folder.But时通知上调了越来越默认sound.Is有任何错误,在code.Could请人帮我。//上按一下按钮,我调用此方法/// 保护无效GenerateNotify(){NotificationManager myNotificationMan...

我复制的MP3(kalimba.mp3)文件到原始文件夹中的资源folder.But时通知上调了越来越默认sound.Is有任何错误,在code.Could请人帮我。

//上按一下按钮,我调用此方法///

 保护无效GenerateNotify(){

    NotificationManager myNotificationManager =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    通知通知=新的通知(android.R.drawable.ic_btn_speak_now,喜,100);
    意向意图=新的意图(getApplicationContext(),as.class);
    PendingIntent contentintent = PendingIntent.getBroadcast(getApplicationContext(),0,意图,0);
    notification.setLatestEventInfo(getApplicationContext(),你好,日,contentintent);
    notification.flags | = Notification.FLAG_AUTO_CANCEL;
    notification.sound = Uri.parse(android.resource://com.example.serviceproject/+ R.raw.kalimba);
    myNotificationManager.notify(NOTIFICATION_ID,通知);
}
 

解决方案

  notification.sound = Uri.parse(android.resource://+ getPackageName()+/ + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;
 

  android 自定义通知铃声设置在哪,安卓手机铃声自定义 短信通知 来电铃声怎么设置 ...

如果定义DEFAULT_SOUND,那么默认的声音覆盖的任何声音

I copied the mp3 (kalimba.mp3) file into raw folder in res folder.But when notification raised its getting default sound.Is there any error in the code.Could anyone please help me.

//on Button click i am calling this method///

protected void GenerateNotify() {

    NotificationManager myNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);  
    Notification notification=new Notification(android.R.drawable.ic_btn_speak_now,"hi",100);
    Intent intent=new Intent(getApplicationContext(),as.class);
    PendingIntent contentintent=PendingIntent.getBroadcast(getApplicationContext(),0, intent, 0);
    notification.setLatestEventInfo(getApplicationContext(), "Hi","date", contentintent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.sound = Uri.parse("android.resource://com.example.serviceproject/" + R.raw.kalimba);
    myNotificationManager.notify(NOTIFICATION_ID,notification);
}

解决方案

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysnd);
notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;

if defined DEFAULT_SOUND, then the default sound overrides any sound

阅读全文

相关推荐

最新文章