-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyService.java
More file actions
45 lines (35 loc) · 1.13 KB
/
MyService.java
File metadata and controls
45 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.iomis.gogavproject;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.provider.Settings;
import android.support.annotation.Nullable;
public class MyService extends Service {
//creating a mediaplayer object
MediaPlayer player;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//getting systems default ringtone
player = MediaPlayer.create(this, R.raw.sound);
//setting loop play to true
//this will make the ringtone continuously playing
player.setLooping(true);
//staring the player
player.start();
//we have some options for service
//start sticky means service will be explicity started and stopped
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
//stopping the player when service is destroyed
player.release();
}
}