2

我设计了一个报警服务应用程序。在该应用程序中,每当警报启动时,它都会显示在通知栏中。问题是,每当我拖动通知栏时,我都想停止警报和通知。

这是我的代码:

if(pYear==pYear2 && pMonth==pMonth2 && pDay==pDay2 && pHour==pHour2 && pMin==pMin2 && pSec==psec2)
{

 Context context = getApplicationContext();

 Intent notifyIntent = new Intent(context, MyAlarmService.class);

 PendingIntent intent1 =PendingIntent.getActivity(MyAlarmService.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
 
 Notification notifyDetails = new Notification(R.drawable.ic_launcher,"New Alert, Click Me!",System.currentTimeMillis());

 notifyDetails.setLatestEventInfo(context, "Alaram", "Get back to Application on clicking me", intent1);

 mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

 AudioManager am=(AudioManager)getSystemService(Context.AUDIO_SERVICE);

am.setMode(AudioManager.MODE_NORMAL);

try
{
    mp.setDataSource(getApplicationContext(), ringtoneUri);
    mp.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
    mp.prepare();
    mp.setLooping(true);
    mp.start();
}
catch(Exception e)
{
    //exception caught in the end zone
}
4

1 回答 1

1

要播放通知声音,您应该使用 notifyDetails.defaults |= Notification.DEFAULT_SOUND;

于 2013-03-08T05:15:57.597 回答