Android: Get Website URL from Running Service

拈花ヽ惹草 提交于 2020-01-06 12:40:58

问题


I understand that a Service class runs in the background in Android and I also understand how to start and stop a service.

I am just trying to get a better idea of how to use a Service.

So say I have a service running in the background. How can I simply get the URL name of a webpage from a web browser app.

Her is my service below:

public class MyService extends Service {

private static final int NOTIF_ID = 1;
private static final String NOTIF_CHANNEL_ID = "Channel_Id";

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // do your jobs here

    startForeground();

    return super.onStartCommand(intent, flags, startId);
}

private void startForeground() {
    Intent notificationIntent = new Intent(this, MainActivity.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    startForeground(NOTIF_ID, new NotificationCompat.Builder(this,
            NOTIF_CHANNEL_ID) // Create a Notification Channel
            .setOngoing(true)
            .setSmallIcon(R.drawable.ic_launcher_background)
            .setContentTitle(getString(R.string.runningtitle))
            .setContentText(getString(R.string.runningtext))
            .setContentIntent(pendingIntent)
            .build());
  }
}

来源:https://stackoverflow.com/questions/54846802/android-get-website-url-from-running-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!