This is a part of my main class:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://xxxxxx.com/songs2/Music%20Promotion/Stream/")) {
try {
songURL = new URL(url);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
filename = songURL.getFile();
startService(new Intent(mainmenu.this, MyService.class));
Now this should get the name of the song being played, but I have a service that starts a notification when the song is playing and I want it to display the name of the file, so how can I pass this variable to my service class?
Here is my service class, I want to display it under contentText where it says “Now Playing…”
public class MyService extends Service {
private static final int HELLO_ID = 1;
private static final String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
}
@Override
public void onStart(Intent intent, int startid) {
Context context2 = getApplicationContext();
CharSequence text = "Buffering...";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context2, text, duration);
toast.show();
mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.notification_icon;
CharSequence tickerText = "Now playing...";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Music Promotion";
CharSequence contentText = "Now Playing...";
Intent notificationIntent = new Intent(this, mainmenu.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(HELLO_ID, notification);
}
@Override
public void onDestroy() {
mNotificationManager.cancel(HELLO_ID);
}
}
I’m not sure if it works with a
Service, but I think you can create aBundlewith theIntentand then get the data from that. Try this in your main class:And then do this in your
Serviceclass, to get the data: