Nitesh Khosla
Nitesh Khosla

Reputation: 875

sound notification

I am using the raw folder contain notification.wav file. When the notification comes in the phone it will be alert of sound notification.wav file.

I am using this code:

Uri path = Uri.parse("android.resource://" + getPackageName() + "/notification.wav");
notification.sound = path;

Please help.

Upvotes: 2

Views: 996

Answers (2)

anoop
anoop

Reputation: 792

String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
        int icon = R.drawable.update;
        CharSequence tickerText = "assignments";
        long when = System.currentTimeMillis();

        Notification assignmentNotification = new Notification(icon, tickerText, when);
       **For sound** assignmentNotification.defaults |= Notification.DEFAULT_SOUND;
        long[] vibrate = {0,100,200,300};
       **For vibrate** assignmentNotification.vibrate = vibrate;
        Context context = getApplicationContext();
        CharSequence contentTitle = "check assignments";
        CharSequence contentText = "chek ur app for assignments ";
        Intent notificationIntent = new Intent(context, ViewAssignmentnotificationActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,0);
        assignmentNotification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
       ** final int id = 2;

Upvotes: 1

Nitesh Khosla
Nitesh Khosla

Reputation: 875

MediaPlayer mMediaPlayer = new MediaPlayer(); 
mMediaPlayer = MediaPlayer.create(this, R.raw.alpha);   
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
mMediaPlayer.setLooping(true); 
mMediaPlayer.start(); 

Upvotes: 0

Related Questions