android.content.Context.startService()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中android.content.Context.startService()方法的一些代码示例,展示了Context.startService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.startService()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:startService

Context.startService介绍

暂无

代码示例

代码示例来源:origin: androidannotations/androidannotations

public ComponentName start() {
  return context.startService(intent);
}

代码示例来源:origin: stackoverflow.com

public class autostart extends BroadcastReceiver 
{
  public void onReceive(Context context, Intent arg1) 
  {
    Intent intent = new Intent(context,service.class);
    context.startService(intent);
    Log.i("Autostart", "started");
  }
}

代码示例来源:origin: stackoverflow.com

public class MyReceiver extends BroadcastReceiver {   

  @Override
  public void onReceive(Context context, Intent intent) {

   Intent myIntent = new Intent(context, YourService.class);
   context.startService(myIntent);

  }
}

代码示例来源:origin: stackoverflow.com

public class StartMyServiceAtBootReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
      Intent serviceIntent = new Intent(context, MyService.class);
      context.startService(serviceIntent);
    }
  }
}

代码示例来源:origin: google/ExoPlayer

private void notifyService() throws Exception {
  Intent intent = getIntent(context, serviceClass, DownloadService.ACTION_INIT);
  try {
   context.startService(intent);
  } catch (IllegalStateException e) {
   /* startService will fail if the app is in the background and the service isn't running. */
   throw new Exception(e);
  }
 }
}

代码示例来源:origin: stackoverflow.com

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ServiceStarter extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    Intent i = new Intent("com.prac.test.MyPersistingService");
    i.setClass(context, MyPersistingService.class);
    context.startService(i);
  }
}

代码示例来源:origin: stackoverflow.com

public class OnBoot extends BroadcastReceiver
{

  @Override
  public void onReceive(Context context, Intent intent) 
  {
    // Create Intent
    Intent serviceIntent = new Intent(context, YourCoolService.class);
    // Start service
    context.startService(serviceIntent);

  }

 }

代码示例来源:origin: nickbutcher/plaid

public static void startActionUpvote(@NonNull Context context, long storyId) {
  final Intent intent = new Intent(context, UpvoteStoryService.class);
  intent.setAction(ACTION_UPVOTE);
  intent.putExtra(EXTRA_STORY_ID, storyId);
  context.startService(intent);
}

代码示例来源:origin: naman14/Timber

public static void asyncNext(final Context context) {
  final Intent previous = new Intent(context, MusicService.class);
  previous.setAction(MusicService.NEXT_ACTION);
  context.startService(previous);
}

代码示例来源:origin: aa112901/remusic

public static void asyncNext(final Context context) {
  final Intent previous = new Intent(context, MediaService.class);
  previous.setAction(MediaService.NEXT_ACTION);
  context.startService(previous);
}

代码示例来源:origin: naman14/Timber

public static void previous(final Context context, final boolean force) {
  final Intent previous = new Intent(context, MusicService.class);
  if (force) {
    previous.setAction(MusicService.PREVIOUS_FORCE_ACTION);
  } else {
    previous.setAction(MusicService.PREVIOUS_ACTION);
  }
  context.startService(previous);
}

代码示例来源:origin: aa112901/remusic

private void pushAction(Context context, String ACTION) {
    Log.e("widget","action = " + ACTION);
    Intent startIntent = new Intent(context,MediaService.class);
    startIntent.setAction(ACTION);
    context.startService(startIntent);
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void onReceive(Context context, Intent intent) {
  Log.e(getClass().getSimpleName(), "HackReceiver onReceive()");

  Intent wrapped=intent.getParcelableExtra(Intent.EXTRA_INTENT);

  context.startService(wrapped);
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

public static void loadDocument(Context ctxt, Uri document) {
 Intent i=new Intent(ctxt, DocumentStorageService.class)
  .setAction(Intent.ACTION_OPEN_DOCUMENT)
  .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
  .setData(document);
 ctxt.startService(i);
}

代码示例来源:origin: google/ExoPlayer

/**
 * Starts the service without adding a new action. If there are any not finished actions and the
 * requirements are met, the service resumes executing actions. Otherwise it stops immediately.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @see #startForeground(Context, Class)
 */
public static void start(Context context, Class<? extends DownloadService> clazz) {
 context.startService(getIntent(context, clazz, ACTION_INIT));
}

代码示例来源:origin: google/ExoPlayer

/**
 * Calls {@link Context#startForegroundService(Intent)} if {@link #SDK_INT} is 26 or higher, or
 * {@link Context#startService(Intent)} otherwise.
 *
 * @param context The context to call.
 * @param intent The intent to pass to the called method.
 * @return The result of the called method.
 */
public static ComponentName startForegroundService(Context context, Intent intent) {
 if (Util.SDK_INT >= 26) {
  return context.startForegroundService(intent);
 } else {
  return context.startService(intent);
 }
}

代码示例来源:origin: naman14/Timber

public void updateService(Bundle extras) {
  if(!MusicPlayer.isPlaybackServiceConnected())return;
  final Intent intent = new Intent(context, MusicService.class);
  intent.setAction(MusicService.UPDATE_PREFERENCES);
  intent.putExtras(extras);
  context.startService(intent);
}

代码示例来源:origin: commonsguy/cw-omnibus

static void startMeUp(Context ctxt, boolean foreground, boolean importantish) {
 Intent i=new Intent(ctxt, DemoService.class)
  .putExtra(EXTRA_FOREGROUND, foreground)
  .putExtra(EXTRA_IMPORTANTISH, importantish);
 if (foreground && Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) {
  ctxt.startForegroundService(i);
 }
 else {
  ctxt.startService(i);
 }
}

代码示例来源:origin: k9mail/k-9

public static void set(Context context, Intent i, Integer wakeLockId) {
  //  Intent i = new Intent();
  i.setClass(context, RemoteControlService.class);
  i.setAction(RemoteControlService.SET_ACTION);
  addWakeLockId(context, i, wakeLockId, true);
  context.startService(i);
}

代码示例来源:origin: android-hacker/VirtualXposed

public static void startup(Context context) {
  File flagFile = context.getFileStreamPath(Constants.NO_NOTIFICATION_FLAG);
  if (Build.VERSION.SDK_INT >= 25 && flagFile.exists()) {
    showNotification = false;
  }
  context.startService(new Intent(context, DaemonService.class));
  if (VirtualCore.get().isServerProcess()) {
    // PrivilegeAppOptimizer.notifyBootFinish();
    DaemonJobService.scheduleJob(context);
  }
}

相关文章

Context类方法