Example usage for android.content Context startService

List of usage examples for android.content Context startService

Introduction

In this page you can find the example usage for android.content Context startService.

Prototype

@Nullable
public abstract ComponentName startService(Intent service);

Source Link

Document

Request that a given application service be started.

Usage

From source file:com.google.android.gcm.GCMRegistrar.java

public static synchronized void internalRegister(Context context, String... senderIds) {
    if (senderIds == null || senderIds.length == 0) {
        throw new IllegalArgumentException("No senderIds");
    }/*from  ww  w  .  ja v a2s.  c om*/
    StringBuilder builder = new StringBuilder(senderIds[0]);
    for (int i = 1; i < senderIds.length; i++) {
        builder.append(',').append(senderIds[i]);
    }
    String senders = builder.toString();
    Log.v(TAG, "Registering app " + context.getPackageName() + " of senders " + senders);
    Intent intent = new Intent(GCMConstants.INTENT_TO_GCM_REGISTRATION);
    intent.setPackage(GSF_PACKAGE);
    intent.putExtra(GCMConstants.EXTRA_APPLICATION_PENDING_INTENT,
            PendingIntent.getBroadcast(context, 0, new Intent(), 0));
    intent.putExtra(GCMConstants.EXTRA_SENDER, senders);
    context.startService(intent);
}

From source file:com.trigger_context.Main_Activity.java

private void Start_NetworkService() {
    if (!Main_Service.wifi) {
        return;/* w  w  w  . ja  v  a 2 s. c om*/
    } else if (Main_Service.wifi && Network_Service.ns != null) {
        // but
        // Network
        // Service
        // is
        // already
        // running
        return;
    }

    Context x = getBaseContext();
    Intent startServiceIntent = new Intent(x, Network_Service.class);
    x.startService(startServiceIntent);
    Toast.makeText(x, "Starting Network_Service", Toast.LENGTH_LONG).show();
}

From source file:com.secupwn.aimsicd.utils.Helpers.java

/**
 * Description:     Deletes the entire database by removing internal SQLite DB file
 *
        //ww w.  jav a2 s . c o  m
 *
 * Dependencies:    Used in AIMSICD.java
 *
 * Notes:           See Android developer info: http://tinyurl.com/psz8vmt
 *
 *              WARNING!
 *              This deletes the entire database, thus any subsequent DB access will FC app.
 *              Therefore we need to either restart app or run AIMSICDDbAdapter, to rebuild DB.
 *              See: #581
 *
 *              In addition, since SQLite is kept in memory during lifetime of App, and
 *              is using Journaling, we have to restart app in order to clear old data
 *              already in memory.
 *
 * @param pContext Context of Activity
 */
public static void askAndDeleteDb(final Context pContext) {
    AlertDialog lAlertDialog = new AlertDialog.Builder(pContext)
            .setNegativeButton(R.string.open_cell_id_button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setPositiveButton(R.string.open_cell_id_button_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Probably put in try/catch in case file removal fails...
                    pContext.stopService(new Intent(pContext, AimsicdService.class));
                    pContext.deleteDatabase("aimsicd.db");
                    new RealmHelper(pContext);
                    pContext.startService(new Intent(pContext, AimsicdService.class));
                    msgLong(pContext, pContext.getString(R.string.delete_database_msg_success));
                }
            }).setMessage(pContext.getString(R.string.clear_database_question))
            .setTitle(R.string.clear_database).setCancelable(false)
            .setIcon(R.drawable.ic_action_delete_database).create();
    lAlertDialog.show();
}

From source file:de.ribeiro.android.gso.core.UntisProvider.java

/**
 * @param ctxt/*from  w  w w. jav  a  2s  . co m*/
 * @param handler
 */
public static void contactStupidService(Context ctxt, Handler handler) {

    Intent intent = new Intent(ctxt, MyService.class);
    if (handler != null) {
        Messenger messenger = new Messenger(handler);
        intent.putExtra("MESSENGER", messenger);

    }
    intent.putExtra("fromFrontend", true);
    ctxt.startService(intent);
}

From source file:org.pixmob.freemobile.netstat.ui.Netstat.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }//from   w  w  w.  j av a2s . co m

    if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null)
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, new StatisticsFragment())
                .commitAllowingStateLoss();

    if (MobileOperator.FREE_MOBILE.isCurrentSimOwner(this) != 1) {
        new UnsupportedSimDialogFragment().show(getSupportFragmentManager(), "error");
        return;
    }

    final Context c = getApplicationContext();
    final Intent i = new Intent(c, MonitorService.class);
    c.startService(i);

    SyncServiceTesting.schedule(this, true);
    SyncService.schedule(this, true);

    final int applicationVersion;
    try {
        applicationVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        // Unlikely to happen.
        throw new RuntimeException("Failed to get application version", e);
    }

    final String versionKey = "version";
    final SharedPreferences prefs = getPreferences(MODE_PRIVATE);
    final int lastKnownVersion = prefs.getInt(versionKey, 0);
    if (lastKnownVersion != applicationVersion) {
        // Store the current application version.
        final SharedPreferences.Editor prefsEditor = prefs.edit();
        prefsEditor.putInt(versionKey, applicationVersion);
        Features.getFeature(SharedPreferencesSaverFeature.class).save(prefsEditor);

        // The application was updated: let's show changelog.
        startActivity(new Intent(this, DocumentBrowser.class).putExtra(DocumentBrowser.INTENT_EXTRA_URL,
                "CHANGELOG.html"));
    }
}

From source file:com.nuvolect.securesuite.webserver.CrypServer.java

public static void enableServer(Context ctx, boolean serverEnabled) {

    m_serverEnabled = serverEnabled;//from ww  w .  ja v a  2 s .  c  o  m
    Intent serverIntent = new Intent(ctx, WebService.class);

    if (serverEnabled) {

        Cryp.put(CConst.SERVER_ENABLED, CConst.TRUE);
        ctx.startService(serverIntent); // Start LAN web server
    } else {
        Cryp.put(CConst.SERVER_ENABLED, CConst.FALSE);
        ctx.stopService(serverIntent); // Stop LAN web server
    }
}

From source file:com.battlelancer.seriesguide.appwidget.AppWidget.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    context.startService(createUpdateIntent(context));
}

From source file:com.battlelancer.seriesguide.appwidget.AppWidget.java

@Override
public void onReceive(Context context, Intent intent) {
    if (REFRESH.equals(intent.getAction())) {
        context.startService(createUpdateIntent(context));
    } else {/*w  w w .ja v a 2  s  . c  om*/
        super.onReceive(context, intent);
    }
}

From source file:de.ribeiro.android.gso.core.UntisProvider.java

/**
 * @param ctxt// w  ww.  j a  v  a 2s. c o m
 * @param handler
 */
public static void contactStupidServiceQuiet(Context ctxt, Handler handler) {

    Intent intent = new Intent(ctxt, MyService.class);
    if (handler != null) {
        Messenger messenger = new Messenger(handler);
        intent.putExtra("MESSENGER", messenger);

    }
    intent.putExtra("fromFrontend", true);
    intent.putExtra("quiet", true);
    ctxt.startService(intent);
}

From source file:com.mindprotectionkit.freephone.monitor.MonitorConfigUpdateReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.w("MonitorConfigUpdateReceiver", "Initiating scheduled monitor config update...");
    Intent serviceIntent = new Intent(context, MonitorConfigUpdateService.class);
    context.startService(serviceIntent);
}