List of usage examples for android.content Context startService
@Nullable public abstract ComponentName startService(Intent service);
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void importKeyPair(final Context context, Uri keypack, String passphrase) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_IMPORT_KEYPAIR); i.putExtra(EXTRA_KEYPACK, keypack);/*from w w w .j ava2s. co m*/ i.putExtra(EXTRA_PASSPHRASE, passphrase); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void requestPresence(final Context context, String to) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_PRESENCE); i.putExtra(MessageCenterService.EXTRA_TO, to); i.putExtra(MessageCenterService.EXTRA_TYPE, Presence.Type.probe.name()); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
/** * Tells the message center we are holding on to it, preventing shutdown for * inactivity./*w ww . j a v a2 s . c o m*/ * @param activate true to wake up from CSI and send become available. */ public static void hold(final Context context, boolean activate) { // increment the application counter ((Kontalk) context.getApplicationContext()).hold(); Intent i = new Intent(context, MessageCenterService.class); i.setAction(ACTION_HOLD); i.putExtra("org.kontalk.activate", activate); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void retryMessagesTo(final Context context, String to) { MessagesProviderUtils.retryMessagesTo(context, to); Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_RETRY); // TODO not implemented yet i.putExtra(MessageCenterService.EXTRA_TO, to); context.startService(i); }
From source file:org.videolan.vlc.RemoteControlClientReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (event != null && action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) { if (event.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK && event.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE && event.getAction() != KeyEvent.ACTION_DOWN) { super.onReceive(context, intent); return; }//w w w . j av a2 s. c o m Intent i = null; switch (event.getKeyCode()) { /* * one click => play/pause * long click => previous * double click => next */ case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: long time = SystemClock.uptimeMillis(); switch (event.getAction()) { case KeyEvent.ACTION_DOWN: if (event.getRepeatCount() <= 0) mHeadsetDownTime = time; break; case KeyEvent.ACTION_UP: if (AndroidDevices.hasTsp()) { //no backward/forward on TV if (time - mHeadsetDownTime >= 1000) { // long click i = new Intent(PlaybackService.ACTION_REMOTE_BACKWARD, null, VLCApplication.getAppContext(), PlaybackService.class); break; } else if (time - mHeadsetUpTime <= 500) { // double click i = new Intent(PlaybackService.ACTION_REMOTE_FORWARD, null, VLCApplication.getAppContext(), PlaybackService.class); break; } } // one click i = new Intent(PlaybackService.ACTION_REMOTE_PLAYPAUSE, null, VLCApplication.getAppContext(), PlaybackService.class); mHeadsetUpTime = time; break; } break; case KeyEvent.KEYCODE_MEDIA_PLAY: context.startService(new Intent(PlaybackService.ACTION_REMOTE_PLAY, null, VLCApplication.getAppContext(), PlaybackService.class)); return; case KeyEvent.KEYCODE_MEDIA_PAUSE: i = new Intent(PlaybackService.ACTION_REMOTE_PAUSE, null, VLCApplication.getAppContext(), PlaybackService.class); break; case KeyEvent.KEYCODE_MEDIA_STOP: i = new Intent(PlaybackService.ACTION_REMOTE_STOP, null, VLCApplication.getAppContext(), PlaybackService.class); break; case KeyEvent.KEYCODE_MEDIA_NEXT: i = new Intent(PlaybackService.ACTION_REMOTE_FORWARD, null, VLCApplication.getAppContext(), PlaybackService.class); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: i = new Intent(PlaybackService.ACTION_REMOTE_BACKWARD, null, VLCApplication.getAppContext(), PlaybackService.class); break; } if (isOrderedBroadcast()) abortBroadcast(); if (i != null) { context.startService(i); return; } } else if (action.equals(PlaybackService.ACTION_REMOTE_PLAYPAUSE)) { intent = new Intent(context, PlaybackService.class); intent.setAction(PlaybackService.ACTION_REMOTE_PLAYPAUSE); context.startService(intent); return; } super.onReceive(context, intent); }
From source file:io.teak.sdk.AppConfiguration.java
public AppConfiguration(@NonNull Context context) { // Teak App Id {/*from ww w. j a v a 2 s .com*/ this.appId = Helpers.getStringResourceByName(TEAK_APP_ID, context); if (this.appId == null) { throw new RuntimeException("Failed to find R.string." + TEAK_APP_ID); } } // Teak API Key { this.apiKey = Helpers.getStringResourceByName(TEAK_API_KEY, context); if (this.apiKey == null) { throw new RuntimeException("Failed to find R.string." + TEAK_API_KEY); } } // Push Sender Id { // TODO: Check ADM vs GCM this.pushSenderId = Helpers.getStringResourceByName(TEAK_GCM_SENDER_ID, context); if (this.pushSenderId == null && Teak.isDebug) { Log.d(LOG_TAG, "R.string." + TEAK_GCM_SENDER_ID + " not present, push notifications disabled."); } } // Package Id { this.bundleId = context.getPackageName(); if (this.bundleId == null) { throw new RuntimeException("Failed to get Bundle Id."); } } PackageManager packageManager = context.getPackageManager(); if (packageManager == null) { throw new RuntimeException("Unable to get Package Manager."); } // App Version { int tempAppVersion = 0; try { tempAppVersion = packageManager.getPackageInfo(this.bundleId, 0).versionCode; } catch (Exception e) { Log.e(LOG_TAG, "Error getting App Version: " + Log.getStackTraceString(e)); } finally { this.appVersion = tempAppVersion; } } // Get the installer package { this.installerPackage = packageManager.getInstallerPackageName(this.bundleId); if (this.installerPackage == null) { Log.e(LOG_TAG, "Installer package (Store) is null, purchase tracking disabled."); } } // Tell the Raven service about the app id try { Intent intent = new Intent(context, RavenService.class); intent.putExtra("appId", this.appId); ComponentName componentName = context.startService(intent); if (componentName == null) { Log.e(LOG_TAG, "Unable to communicate with exception reporting service. Please add:\n\t<service android:name=\"io.teak.sdk.service.RavenService\" android:process=\":teak.raven\" android:exported=\"false\"/>\nTo the <application> section of your AndroidManifest.xml"); } else if (Teak.isDebug) { Log.d(LOG_TAG, "Communication with exception reporting service established: " + componentName.toString()); } } catch (Exception e) { Log.e(LOG_TAG, "Error calling startService for exception reporting service: " + Log.getStackTraceString(e)); } }
From source file:github.popeen.dsub.service.DownloadService.java
public static void startService(Context context, Intent intent) { PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE); if (Build.VERSION.SDK_INT < 26 || (powerManager != null && powerManager.isIgnoringBatteryOptimizations(intent.getPackage()))) { context.startService(intent); } else {/*w ww. j a va 2 s .c o m*/ context.startForegroundService(intent); } }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
/** Sends a chat state message. */ public static void sendChatState(final Context context, String to, ChatState state) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_MESSAGE); i.putExtra("org.kontalk.message.to", to); i.putExtra("org.kontalk.message.chatState", state.name()); i.putExtra("org.kontalk.message.standalone", true); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void start(Context context) { // check for offline mode if (isOfflineMode(context)) { Log.d(TAG, "offline mode enable - abort service start"); return;//from www .ja va 2s. co m } // check for network state if (SystemUtils.isNetworkConnectionAvailable(context)) { Log.d(TAG, "starting message center"); final Intent intent = getStartIntent(context); context.startService(intent); } else Log.d(TAG, "network not available or background data disabled - abort service start"); }
From source file:com.gcm.client.GcmHelper.java
/** * Initialize the GcmHelper class. To be called from the application class onCreate or from the * onCreate of the main activity/*from w ww. j a v a 2 s.c om*/ * * @param context An instance of the Application Context */ public synchronized void init(@NonNull Context context) { if (!isGooglePlayservicesAvailable(context)) { throw new IllegalArgumentException("Not using the recommended Play Services version"); } //get the GCM sender id from strings.xml if (TextUtils.isEmpty(senderID)) { int id = context.getResources().getIdentifier("gcm_authorized_entity", "string", context.getPackageName()); senderID = context.getResources().getString(id); } if (TextUtils.isEmpty(senderID)) { throw new IllegalArgumentException("No SenderId provided!! Cannot instantiate"); } SharedPreferences localPref = getSharedPreference(context); //get topics array if (localPref.contains(PREF_KEY_SUBSCRIPTION)) { String subscription = localPref.getString(PREF_KEY_SUBSCRIPTION, null); if (!TextUtils.isEmpty(subscription)) { try { JSONArray array = new JSONArray(subscription); int length = array.length(); topics = new ArrayList<>(); for (int i = 0; i < length; i++) { topics.add(array.getString(i)); } } catch (JSONException ignored) { if (DEBUG_ENABLED) Log.e(TAG, "init: while processing subscription list", ignored); } } } boolean registrationReq = true; if (localPref.contains(PREF_KEY_TOKEN)) { pushToken = localPref.getString(PREF_KEY_TOKEN, null); if (!TextUtils.isEmpty(pushToken)) { registrationReq = false; //don't pass token if already present } } if (registrationReq) { //register for push token Intent registration = new Intent(context, RegistrationIntentService.class); registration.setAction(RegistrationIntentService.ACTION_REGISTER); context.startService(registration); } //check if debug build and enable DEBUG MODE DEBUG_ENABLED = (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)); initialized = true; }