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 setGroupSubject(final Context context, String groupJid, String groupSubject, String[] to, boolean encrypt, long msgId, String packetId) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_MESSAGE); i.putExtra("org.kontalk.message.msgId", msgId); i.putExtra("org.kontalk.message.packetId", packetId); i.putExtra("org.kontalk.message.mime", GroupCommandComponent.MIME_TYPE); i.putExtra("org.kontalk.message.group.jid", groupJid); i.putExtra("org.kontalk.message.group.subject", groupSubject); i.putExtra("org.kontalk.message.group.command", GROUP_COMMAND_SUBJECT); i.putExtra("org.kontalk.message.to", to); i.putExtra("org.kontalk.message.encrypt", encrypt); i.putExtra("org.kontalk.message.chatState", ChatState.active.name()); context.startService(i); }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
@Override public void onReceive(Context context, Intent intent) { final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // Get user preferences final SharedPreferences sharedPrefs = context.getSharedPreferences(Const.APP_PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences.Editor sharedPrefsEditor = sharedPrefs.edit(); final boolean hasNotifications = sharedPrefs.getBoolean(Const.PrefsNames.HAS_NOTIFICATIONS, false); final boolean hasVibration = (sharedPrefs.getBoolean(Const.PrefsNames.HAS_VIBRATION, false) && vibrator.hasVibrator()); final boolean hasSound = sharedPrefs.getBoolean(Const.PrefsNames.HAS_SOUND, false); final boolean onScreenLock = sharedPrefs.getBoolean(Const.PrefsNames.ON_SCREEN_LOCK, true); final boolean onPowerLoss = sharedPrefs.getBoolean(Const.PrefsNames.ON_POWER_LOSS, false); final int delayToLock = Integer.parseInt( sharedPrefs.getString(Const.PrefsNames.DELAY_TO_LOCK, Const.PrefsValues.DELAY_FAST)) * 1000; final int notifyCount = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_COUNT, 1); final int notifyGroup = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_GROUP, 1); final String action = intent.getAction(); if (action == null) return;/*from w w w . j a v a 2 s. com*/ if (action.equals(Const.IntentActions.NOTIFY_DELETE)) { if (hasNotifications) { // Reset the notification counter (and group) on NOTIFY_DELETE sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, 1); sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_GROUP, notifyGroup + 1); sharedPrefsEditor.apply(); } } else if (action.equals(Intent.ACTION_POWER_CONNECTED) || action.equals(Intent.ACTION_POWER_DISCONNECTED)) { final boolean isConnectedPower = action.equals(Intent.ACTION_POWER_CONNECTED); // Lock the screen, following the user preferences if (delayToLock == 0) { LockScreenHelper.lockScreen(context, onScreenLock, onPowerLoss, isConnectedPower); } else { Intent intentService = new Intent(Intent.ACTION_SYNC, null, context, DelayedLockService.class); Bundle extras = new Bundle(); extras.putBoolean(Const.IntentExtras.ON_SCREEN_LOCK, onScreenLock); extras.putBoolean(Const.IntentExtras.ON_POWER_LOSS, onPowerLoss); extras.putBoolean(Const.IntentExtras.IS_CONNECTED, isConnectedPower); extras.putInt(Const.IntentExtras.DELAY_TO_LOCK, delayToLock); intentService.putExtras(extras); context.startService(intentService); } // Save in database saveHistoryItem(context.getApplicationContext(), isConnectedPower, notifyGroup); if (hasNotifications) { // Send notification, with sound and vibration notify(context, isConnectedPower, hasVibration, hasSound, notifyCount); // Increment the notification counter sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, notifyCount + 1); sharedPrefsEditor.apply(); } else { // Native Vibration or Sound, without Notifications nativeVibrate(context, hasVibration); nativeRingtone(context, hasSound); } } }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
/** Sends a binary message. */ public static void sendBinaryMessage(final Context context, String to, String mime, Uri localUri, long length, String previewPath, boolean encrypt, int compress, long msgId, String packetId) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_MESSAGE); i.putExtra("org.kontalk.message.msgId", msgId); i.putExtra("org.kontalk.message.packetId", packetId); i.putExtra("org.kontalk.message.mime", mime); i.putExtra("org.kontalk.message.to", to); i.putExtra("org.kontalk.message.media.uri", localUri.toString()); i.putExtra("org.kontalk.message.length", length); i.putExtra("org.kontalk.message.preview.path", previewPath); i.putExtra("org.kontalk.message.compress", compress); i.putExtra("org.kontalk.message.encrypt", encrypt); i.putExtra("org.kontalk.message.chatState", ChatState.active.name()); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void addGroupMembers(final Context context, String groupJid, String groupSubject, String[] to, String[] members, boolean encrypt, long msgId, String packetId) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_MESSAGE); i.putExtra("org.kontalk.message.msgId", msgId); i.putExtra("org.kontalk.message.packetId", packetId); i.putExtra("org.kontalk.message.mime", GroupCommandComponent.MIME_TYPE); i.putExtra("org.kontalk.message.group.jid", groupJid); i.putExtra("org.kontalk.message.group.subject", groupSubject); i.putExtra("org.kontalk.message.group.command", GROUP_COMMAND_MEMBERS); i.putExtra("org.kontalk.message.group.add", members); i.putExtra("org.kontalk.message.to", to); i.putExtra("org.kontalk.message.encrypt", encrypt); i.putExtra("org.kontalk.message.chatState", ChatState.active.name()); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void removeGroupMembers(final Context context, String groupJid, String groupSubject, String[] to, String[] members, boolean encrypt, long msgId, String packetId) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_MESSAGE); i.putExtra("org.kontalk.message.msgId", msgId); i.putExtra("org.kontalk.message.packetId", packetId); i.putExtra("org.kontalk.message.mime", GroupCommandComponent.MIME_TYPE); i.putExtra("org.kontalk.message.group.jid", groupJid); i.putExtra("org.kontalk.message.group.subject", groupSubject); i.putExtra("org.kontalk.message.group.command", GROUP_COMMAND_MEMBERS); i.putExtra("org.kontalk.message.group.remove", members); i.putExtra("org.kontalk.message.to", to); i.putExtra("org.kontalk.message.encrypt", encrypt); i.putExtra("org.kontalk.message.chatState", ChatState.active.name()); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void sendUploadedMedia(final Context context, String to, String mime, Uri localUri, long length, String previewPath, String fetchUrl, boolean encrypt, long msgId, String packetId) { Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_MESSAGE); i.putExtra("org.kontalk.message.msgId", msgId); i.putExtra("org.kontalk.message.packetId", packetId); i.putExtra("org.kontalk.message.mime", mime); i.putExtra("org.kontalk.message.to", to); i.putExtra("org.kontalk.message.preview.uri", localUri.toString()); i.putExtra("org.kontalk.message.length", length); i.putExtra("org.kontalk.message.preview.path", previewPath); i.putExtra("org.kontalk.message.body", fetchUrl); i.putExtra("org.kontalk.message.fetch.url", fetchUrl); i.putExtra("org.kontalk.message.encrypt", encrypt); i.putExtra("org.kontalk.message.chatState", ChatState.active.name()); context.startService(i); }
From source file:org.kontalk.service.msgcenter.MessageCenterService.java
public static void sendGroupBinaryMessage(final Context context, String groupJid, String[] to, String mime, Uri localUri, long length, String previewPath, boolean encrypt, int compress, long msgId, String packetId) {/*w ww. j a va 2s .co m*/ Intent i = new Intent(context, MessageCenterService.class); i.setAction(MessageCenterService.ACTION_MESSAGE); i.putExtra("org.kontalk.message.msgId", msgId); i.putExtra("org.kontalk.message.packetId", packetId); i.putExtra("org.kontalk.message.mime", mime); i.putExtra("org.kontalk.message.group.jid", groupJid); i.putExtra("org.kontalk.message.to", to); i.putExtra("org.kontalk.message.media.uri", localUri.toString()); i.putExtra("org.kontalk.message.length", length); i.putExtra("org.kontalk.message.preview.path", previewPath); i.putExtra("org.kontalk.message.compress", compress); i.putExtra("org.kontalk.message.encrypt", encrypt); i.putExtra("org.kontalk.message.chatState", ChatState.active.name()); context.startService(i); }
From source file:fr.bmartel.android.tictactoe.GameSingleton.java
private GameSingleton(Context context) { this.context = context.getApplicationContext(); this.executor = Executors.newFixedThreadPool(1); //queue = Volley.newRequestQueue(context.getApplicationContext()); HttpStack hurlStack = new HurlStack() { @Override/*from w ww . j a v a 2 s . com*/ protected HttpURLConnection createConnection(URL url) throws IOException { HttpsURLConnection httpsURLConnection = (HttpsURLConnection) super.createConnection(url); try { httpsURLConnection.setSSLSocketFactory(SSLCertificateSocketFactory.getInsecure(0, null)); httpsURLConnection.setHostnameVerifier(new AllowAllHostnameVerifier()); } catch (Exception e) { e.printStackTrace(); } return httpsURLConnection; } }; queue = Volley.newRequestQueue(context, hurlStack); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); //load device id from shared preference DEVICE_ID = sharedPreferences.getString(RequestConstants.DEVICE_ID, ""); deviceName = sharedPreferences.getString(RequestConstants.DEVICE_NAME, RequestConstants.DEFAULT_USERNAME); if (DEVICE_ID.equals("")) { //register deviceId in shared preference SharedPreferences.Editor editor = sharedPreferences.edit(); DEVICE_ID = new RandomGen(DEVICE_ID_SIZE).nextString(); editor.putString(RequestConstants.DEVICE_ID, DEVICE_ID); editor.commit(); } JsonObjectRequest jsObjRequest = new JsonObjectRequest(BuildConfig.APP_ROUTE + "/connect", RequestBuilder.buildConnectionRequest(DEVICE_ID, deviceName), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.i(TAG, "response received connect : " + response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub error.printStackTrace(); } }); jsObjRequest.setShouldCache(false); queue.add(jsObjRequest); Log.i(TAG, "device id " + DEVICE_ID + " initialized"); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(context, RegistrationIntentService.class); context.startService(intent); } }
From source file:com.cyanogenmod.eleven.AhuButtonIntentReceiver.java
/** * {@inheritDoc}//from ww w . j a v a 2 s . c o m */ @Override public void onReceive(final Context context, final Intent intent) { if (!MusicUtils.isPlaybackServiceConnected()) { if (DEBUG) Log.v(TAG, "Received intent: " + intent + ":" + intent.getAction() + ":" + intent.getIntExtra("keyCode", 0) + " but no service running"); return; } if (MusicPlaybackService.mBtLock) { if (DEBUG) Log.v(TAG, "Received intent: " + intent + ":" + intent.getAction() + ":" + intent.getIntExtra("keyCode", 0) + " but BTLock is on!"); return; } if (DEBUG) Log.v(TAG, "Received intent: " + intent + ":" + intent.getAction() + ":" + intent.getIntExtra("keyCode", 0)); final String intentAction = intent.getAction(); final int keyCode = intent.getIntExtra("keyCode", 0); if (ACTION_AHU_KEYDOWN.equals(intentAction)) { String command = null; String action = MusicPlaybackService.SERVICECMD; switch (keyCode) { case KEYCODE_AHU_BUTTON_STOP: command = MusicPlaybackService.CMDSTOP; break; case KEYCODE_AHU_BUTTON_PLAYPAUSE: command = MusicPlaybackService.CMDTOGGLEPAUSE; break; case KEYCODE_AHU_BUTTON_NEXT: case KEYCODE_AHU_BUTTON_NEXT_1: case KEYCODE_AHU_BUTTON_NEXT_2: case KEYCODE_AHU_BUTTON_NEXT_3: command = MusicPlaybackService.CMDNEXT; break; case KEYCODE_AHU_BUTTON_PREV: case KEYCODE_AHU_BUTTON_PREV_1: case KEYCODE_AHU_BUTTON_PREV_2: case KEYCODE_AHU_BUTTON_PREV_3: command = MusicPlaybackService.CMDPREVIOUS; break; case KEYCODE_AHU_BUTTON_REPEAT_MODE: action = MusicPlaybackService.REPEAT_ACTION; break; case KEYCODE_AHU_BUTTON_SETTRACK_0: case KEYCODE_AHU_BUTTON_SETTRACK_1: case KEYCODE_AHU_BUTTON_SETTRACK_2: case KEYCODE_AHU_BUTTON_SETTRACK_3: case KEYCODE_AHU_BUTTON_SETTRACK_4: case KEYCODE_AHU_BUTTON_SETTRACK_5: case KEYCODE_AHU_BUTTON_SETTRACK_6: case KEYCODE_AHU_BUTTON_SETTRACK_7: case KEYCODE_AHU_BUTTON_SETTRACK_8: case KEYCODE_AHU_BUTTON_SETTRACK_9: command = MusicPlaybackService.CMDSETTRACK; break; } if (command != null) { final Intent i = new Intent(context, MusicPlaybackService.class); i.setAction(action); i.putExtra(MusicPlaybackService.CMDNAME, command); if (MusicPlaybackService.CMDSETTRACK.equals(command)) { i.putExtra("track", keyCode - 282); } i.putExtra(MusicPlaybackService.FROM_AHU_BUTTON, true); context.startService(i); } } }