Example usage for android.os SystemClock elapsedRealtime

List of usage examples for android.os SystemClock elapsedRealtime

Introduction

In this page you can find the example usage for android.os SystemClock elapsedRealtime.

Prototype

@CriticalNative
native public static long elapsedRealtime();

Source Link

Document

Returns milliseconds since boot, including time spent in sleep.

Usage

From source file:com.android.profilerapp.network.NetworkFragment.java

private void download() {
    Thread downloadThread = new Thread(new Runnable() {
        @Override//from  ww  w  .  j  a  va2  s.c o m
        public void run() {
            long timeStart = SystemClock.elapsedRealtime();
            URL url;
            try {
                int next = myNumDownloadsTotal.getAndIncrement() % DownloadUrls.IMAGE_URLS.length;
                url = new URL(DownloadUrls.IMAGE_URLS[next]);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                return;
            }

            HttpURLConnection connection;
            try {
                connection = (HttpURLConnection) url.openConnection();
                // Client closes the socket on its end once it receives the server response. We do not need connection reusing.
                connection.setRequestProperty("Connection", "Close");
                String urlString = url.toString();
                Log.d(TAG, String.format("Connection opened [%d %d]: %s", myUid, Thread.currentThread().getId(),
                        urlString));
                BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
                while (in.read() != -1) {
                }
                Log.d(TAG,
                        String.format("Finished %d / %d (time %d ms): %s",
                                myNumDownloadsSoFar.incrementAndGet(), myNumDownloadsTotal.get(),
                                SystemClock.elapsedRealtime() - timeStart, urlString));
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
            connection.disconnect();
        }
    });
    downloadThread.start();
}

From source file:at.alladin.rmbt.android.test.RMBTLoopService.java

public void triggerTest() {
    loopModeResults.setStatus(Status.RUNNING);
    isRunning.set(true);/*from w  ww .  j  a  v  a 2s.c om*/
    loopModeResults.setNumberOfTests(loopModeResults.getNumberOfTests() + 1);
    lastTestLocation = lastLocation;
    loopModeResults.setLastDistance(0);
    loopModeResults.setLastTestTime(SystemClock.elapsedRealtime());
    final Intent service = new Intent(RMBTService.ACTION_LOOP_TEST, null, this, RMBTService.class);
    ConfigHelper.setLoopModeTestCounter(getApplicationContext(), loopModeResults.getNumberOfTests());
    startService(service);
    updateNotification();
}

From source file:com.mr.http.toolbox.MR_BasicNetwork.java

protected void logError(String what, String url, long start) {
    long now = SystemClock.elapsedRealtime();
    MR_VolleyLog.v("HTTP ERROR(%s) %d ms to fetch %s", what, (now - start), url);
}

From source file:alaindc.crowdroid.SensorsIntentService.java

public void stub_onSensorChanged(int typeSensor) {
    if (typeSensor < 0)
        return;//from   www .  j  a v a 2 s .  com

    float value, minf, maxf;
    switch (typeSensor) {
    case Sensor.TYPE_AMBIENT_TEMPERATURE:
        minf = -20;
        maxf = 42;
        break;
    case Sensor.TYPE_PRESSURE: // https://it.wikipedia.org/wiki/Pressione_atmosferica
        minf = 870;
        maxf = 1085;
        break;
    case Sensor.TYPE_RELATIVE_HUMIDITY:
        minf = 30;
        maxf = 100;
        break;
    default:
        minf = 0;
        maxf = 0;
        break;
    }

    value = random.nextFloat() * (maxf - minf) + minf;

    int index = Constants.getIndexAlarmForSensor(typeSensor);

    SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
            Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString(Constants.PREF_SENSOR_ + typeSensor, Float.toString(value));
    editor.commit();

    // Update view
    Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
    senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA,
            "Sensor " + Constants.getNameOfSensor(typeSensor) + " value: " + Float.toString(value));
    LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent);

    // Set the alarm random
    alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class);
    intentAlarm.setAction(Constants.INTENT_STUB_SENSOR_CHANGED + typeSensor);
    intentAlarm.putExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, typeSensor);
    alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0);

    // TODO Set timeout time from server indications
    int seconds = random.nextInt(50) + 10; // 10/60 sec
    alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000,
            alarmIntent);
}

From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderPreN.java

@Override
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) {
    final Timer timer = unexpired.get(0);
    final long remainingTime = timer.getRemainingTime();

    // Generate some descriptive text, a title, and some actions based on timer states.
    final String contentText;
    final String contentTitle;
    @DrawableRes//from  www  .j a  va 2 s  . co m
    int firstActionIconId, secondActionIconId = 0;
    @StringRes
    int firstActionTitleId, secondActionTitleId = 0;
    Intent firstActionIntent, secondActionIntent = null;

    if (unexpired.size() == 1) {
        contentText = formatElapsedTimeUntilExpiry(context, remainingTime);

        if (timer.isRunning()) {
            // Single timer is running.
            if (TextUtils.isEmpty(timer.getLabel())) {
                contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_notification_label);
            } else {
                contentTitle = timer.getLabel();
            }

            firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_pause_24dp;
            firstActionTitleId = com.wizardsofm.deskclock.R.string.timer_pause;
            firstActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            secondActionIconId = com.wizardsofm.deskclock.R.drawable.ic_add_24dp;
            secondActionTitleId = com.wizardsofm.deskclock.R.string.timer_plus_1_min;
            secondActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());
        } else {
            // Single timer is paused.
            contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_paused);

            firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_start_24dp;
            firstActionTitleId = com.wizardsofm.deskclock.R.string.sw_resume_button;
            firstActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            secondActionIconId = com.wizardsofm.deskclock.R.drawable.ic_reset_24dp;
            secondActionTitleId = com.wizardsofm.deskclock.R.string.sw_reset_button;
            secondActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());
        }
    } else {
        if (timer.isRunning()) {
            // At least one timer is running.
            final String timeRemaining = formatElapsedTimeUntilExpiry(context, remainingTime);
            contentText = context.getString(com.wizardsofm.deskclock.R.string.next_timer_notif, timeRemaining);
            contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timers_in_use, unexpired.size());
        } else {
            // All timers are paused.
            contentText = context.getString(com.wizardsofm.deskclock.R.string.all_timers_stopped_notif);
            contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timers_stopped,
                    unexpired.size());
        }

        firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_reset_24dp;
        firstActionTitleId = com.wizardsofm.deskclock.R.string.timer_reset_all;
        firstActionIntent = TimerService.createResetUnexpiredTimersIntent(context);
    }

    // Intent to load the app and show the timer when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS)
            .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId())
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL,
                    com.wizardsofm.deskclock.R.string.label_notification);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true)
            .setLocalOnly(true).setShowWhen(false).setAutoCancel(false).setContentText(contentText)
            .setContentTitle(contentTitle).setContentIntent(pendingShowApp)
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background));

    final PendingIntent action1 = Utils.pendingServiceIntent(context, firstActionIntent);
    final String action1Title = context.getString(firstActionTitleId);
    builder.addAction(firstActionIconId, action1Title, action1);

    if (secondActionIntent != null) {
        final PendingIntent action2 = Utils.pendingServiceIntent(context, secondActionIntent);
        final String action2Title = context.getString(secondActionTitleId);
        builder.addAction(secondActionIconId, action2Title, action2);
    }

    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final Intent updateNotification = TimerService.createUpdateNotificationIntent(context);
    if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) {
        // Schedule a callback to update the time-sensitive information of the running timer.
        final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

        final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS;
        final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange;
        TimerModel.schedulePendingIntent(am, triggerTime, pi);
    } else {
        // Cancel the update notification callback.
        final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE);
        if (pi != null) {
            am.cancel(pi);
            pi.cancel();
        }
    }

    return builder.build();
}

From source file:org.kegbot.api.KegbotApiImpl.java

private JsonNode requestJson(Request request) throws KegbotApiException {
    final Response response;
    final long startTime = SystemClock.elapsedRealtime();
    try {//from   w w  w . j  a  va2s. c om
        response = mClient.newCall(request).execute();
    } catch (IOException e) {
        Log.w(TAG, String.format("--> %s %s [ERR]", request.method(), request.urlString()));
        throw new KegbotApiException(e);
    }
    final long endTime = SystemClock.elapsedRealtime();

    final int responseCode = response.code();
    final String logMessage = String.format("--> %s %s [%s] %sms", request.method(), request.urlString(),
            responseCode, endTime - startTime);
    if (responseCode >= 200 && responseCode < 300) {
        Log.d(TAG, logMessage);
    } else {
        Log.w(TAG, logMessage);
    }
    final ResponseBody body = response.body();

    final JsonNode rootNode;
    try {
        try {
            final ObjectMapper mapper = new ObjectMapper();
            rootNode = mapper.readValue(body.byteStream(), JsonNode.class);
        } finally {
            body.close();
        }
    } catch (JsonParseException e) {
        throw new KegbotApiMalformedResponseException(e);
    } catch (JsonMappingException e) {
        throw new KegbotApiMalformedResponseException(e);
    } catch (IOException e) {
        throw new KegbotApiException(e);
    }

    boolean success = false;
    try {
        // Handle structural errors.
        if (!rootNode.has("meta")) {
            throw new KegbotApiMalformedResponseException("Response is missing 'meta' field.");
        }
        final JsonNode meta = rootNode.get("meta");
        if (!meta.isContainerNode()) {
            throw new KegbotApiMalformedResponseException("'meta' field is wrong type.");
        }

        final String message;
        if (rootNode.has("error") && rootNode.get("error").has("message")) {
            message = rootNode.get("error").get("message").getTextValue();
        } else {
            message = null;
        }

        // Handle HTTP errors.
        if (responseCode < 200 || responseCode >= 400) {
            switch (responseCode) {
            case 401:
                throw new NotAuthorizedException(message);
            case 404:
                throw new KegbotApi404(message);
            case 405:
                throw new MethodNotAllowedException(message);
            default:
                if (message != null) {
                    throw new KegbotApiServerError(message);
                } else {
                    throw new KegbotApiServerError("Server error, response code=" + responseCode);
                }
            }
        }

        success = true;
        return rootNode;
    } finally {
        if (!success) {
            Log.d(TAG, "Response JSON was: " + rootNode.toString());
        }
    }
}

From source file:edu.rutgers.winlab.crowdpp.ui.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.home_fragment_layout, container, false);

    tb_cal = (ToggleButton) view.findViewById(R.id.tb_home_calibration);
    tb_service = (ToggleButton) view.findViewById(R.id.tb_home_service);
    tb_test = (ToggleButton) view.findViewById(R.id.tb_home_test);
    tv_cal_content = (TextView) view.findViewById(R.id.tv_home_calibration_content);
    tv_cal_text = (TextView) view.findViewById(R.id.tv_home_calibration_text);
    tv_debug = (TextView) view.findViewById(R.id.tv_home_test_debug);
    tv_record = (TextView) view.findViewById(R.id.tv_home_test_record);
    timer_cal = (Chronometer) view.findViewById(R.id.timer_calibration);
    timer_test = (Chronometer) view.findViewById(R.id.timer_test);
    rl_service = (RelativeLayout) view.findViewById(R.id.rl_home_service);
    rl_test = (RelativeLayout) view.findViewById(R.id.rl_home_test);
    if (isMyServiceRunning() == true)
        tb_service.setChecked(true);/*from  w  w  w. j ava2  s  .  c om*/

    if (Constants.calibration())
        tv_cal_content.setText("You are all set for the calibration.");

    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        Toast.makeText(getActivity(), "Can not find SD card ...", Toast.LENGTH_SHORT).show();
        getActivity().finish();
    }

    crowdppDir = new File(Constants.crowdppPath);
    if (!crowdppDir.exists() || !crowdppDir.isDirectory()) {
        crowdppDir.mkdir();
    }

    testDir = new File(Constants.testPath);
    if (!testDir.exists() || !testDir.isDirectory()) {
        testDir.mkdir();
    }

    calWavFile = crowdppDir + "/" + Constants.PHONE_ID + ".wav";

    timer_cal.setVisibility(View.INVISIBLE);
    timer_test.setVisibility(View.INVISIBLE);

    mDatabase = new DataBaseHelper(getActivity().getApplicationContext());
    mDB = mDatabase.getWritableDatabase();

    gps = new LocationTracker(getActivity().getApplicationContext());

    s3Client = new AmazonS3Client(new BasicAWSCredentials(Constants.ACCESS_KEY_ID, Constants.SECRET_KEY));
    s3Client.setRegion(Region.getRegion(Regions.US_WEST_2));

    tb_cal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // prevent the calibration button being pressed when either and test or service is running 
            if (tb_service.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show();
                tb_cal.setChecked(false);
            } else if (tb_test.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show();
                tb_cal.setChecked(false);
            }
            // calibration
            else {
                if (isChecked) {
                    tv_cal_text.setText(Constants.cal_text);
                    rl_service.setVisibility(View.INVISIBLE);
                    rl_test.setVisibility(View.INVISIBLE);
                    timer_cal.setVisibility(View.VISIBLE);

                    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
                    dialog.setTitle("Calibration");
                    dialog.setMessage(Constants.cal_dialog);
                    dialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            timer_cal.setBase(SystemClock.elapsedRealtime());
                            timer_cal.start();
                            tv_cal_content.setText("Recording your voice...");

                            Bundle mbundle = new Bundle();
                            mbundle.putString("audiopath", calWavFile);
                            Log.i("HomeFragment", "start audio recording service");

                            // delete the existing calibration data before the recalibration 
                            FileProcess.deleteFile(calWavFile);
                            FileProcess.deleteFile(calWavFile + ".jstk.mfcc.txt");
                            FileProcess.deleteFile(calWavFile + ".YIN.pitch.txt");

                            // start audio recording
                            Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                            recordIntent.putExtras(mbundle);
                            getActivity().startService(recordIntent);
                        }
                    });
                    dialog.show();
                    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20);
                } else {
                    // stop audio recording
                    Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                    getActivity().stopService(recordIntent);
                    timer_cal.stop();
                    tb_cal.setClickable(false);
                    tv_cal_content.setText("Calibrating....");
                    // start calibration
                    new Calibration().execute();
                    tb_cal.setClickable(true);
                    tv_cal_text.setText("");
                    rl_service.setVisibility(View.VISIBLE);
                    rl_test.setVisibility(View.VISIBLE);
                    timer_cal.setVisibility(View.INVISIBLE);
                }
            }
        }
    });

    tb_service.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // prevent the service button being pressed when either and test or calibration is running           
            if (tb_cal.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show();
                tb_service.setChecked(false);
            } else if (tb_test.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show();
                tb_service.setChecked(false);
            }
            // speaker counting service
            else {
                Intent countIntent = new Intent(getActivity(), SpeakerCountService.class);
                if (isChecked) {
                    getActivity().startService(countIntent);
                } else {
                    getActivity().stopService(countIntent);
                }
            }
        }
    });

    tb_test.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // prevent the test button being pressed when either and service or calibration is running           
            if (tb_cal.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show();
                tb_test.setChecked(false);
            } else if (tb_service.isChecked()) {
                Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show();
                tb_test.setChecked(false);
            }
            // perform the speaker counting test
            else {
                if (isChecked) {
                    // get location information
                    gps.getLocation();
                    if (gps.canGetLocation()) {
                        latitude = gps.getLatitude();
                        longitude = gps.getLongitude();
                    } else {
                        latitude = -1;
                        longitude = -1;
                    }
                    gps.stopUsingGPS();

                    timer_test.setBase(SystemClock.elapsedRealtime());
                    timer_test.start();
                    tv_debug.setText("Recording...");
                    testWavFile = testDir + "/" + FileProcess.newFileOnTime("wav");
                    // start audio recording
                    Bundle mbundle = new Bundle();
                    mbundle.putString("audiopath", testWavFile);
                    Log.i("HomeFragment", "start audio recording service");
                    Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                    recordIntent.putExtras(mbundle);
                    date = Now.getDate();
                    start = Now.getTimeOfDay();
                    getActivity().startService(recordIntent);
                    timer_test.setVisibility(View.VISIBLE);
                } else {
                    // stop audio recording
                    Intent recordIntent = new Intent(getActivity(), AudioRecordService.class);
                    getActivity().stopService(recordIntent);
                    timer_test.stop();
                    end = Now.getTimeOfDay();
                    tb_test.setClickable(false);
                    // start speaker counting test
                    new Test().execute();
                    timer_test.setVisibility(View.INVISIBLE);
                    tb_test.setClickable(true);
                }
            }
        }
    });
    return view;
}

From source file:com.android.im.imps.HttpDataChannel.java

public long sendHeartbeat() {
    if (mSuspended) {
        return 0;
    }//from w w  w  . j  av  a 2 s .com

    long inactiveTime = SystemClock.elapsedRealtime() - mLastActive;
    if (needSendKeepAlive(inactiveTime)) {
        sendKeepAlive();
        return mKeepAliveMillis;
    } else {
        return mKeepAliveMillis - inactiveTime;
    }
}

From source file:com.hackerati.android.user_sdk.volley.HBasicNetwork.java

protected void logError(final String what, final String url, final long start) {
    final long now = SystemClock.elapsedRealtime();
    VolleyLog.v("HTTP ERROR(%s) %d ms to fetch %s", what, (now - start), url);
}

From source file:com.ayaseya.padnotification.GcmIntentService.java

@Override
protected void onHandleIntent(final Intent intent) {

    extras = intent.getExtras();/*from   w  w w.j  a  v a2s .c  om*/

    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    //      displayMessage(this, extras.toString());

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            //                sendNotification("Send error: " + extras.toString());
            Log.v(TAG, "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            //                sendNotification("Deleted messages on server: " + extras.toString());
            Log.v(TAG, "Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            for (int i = 0; i < 5; i++) {
                Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                }
            }
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.

            // ?????IntentService????????
            // ?????????
            new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                    //                  Log.v(TAG, "doInBackground()");

                    // soundPool?????
                    soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
                    // soundPool??Listener??????
                    soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {

                        @Override
                        public void onLoadComplete(final SoundPool soundPool, int sampleId, int status) {
                            if (status == 0) {

                                if (notificationPermission) {// ????????

                                    // Notification????
                                    sendNotification("??????"
                                            + extras.get("INDEX") + "??", intent);

                                    //??????????

                                    if (isPlugged) {// ???????
                                        Log.v(TAG, "??????");
                                        if (ringerMode) {// 
                                            Log.v(TAG, "");
                                            if (checkbox_sound) {
                                                soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F);
                                            }
                                            if (checkbox_vibration) {
                                                vibrator.vibrate(1500);
                                            }

                                        } else if (vibrateMode) {// 
                                            Log.v(TAG, "");
                                            if (checkbox_vibration) {
                                                vibrator.vibrate(1500);
                                            }

                                        } else if (silentMode) {// 
                                            Log.v(TAG, "");
                                            if (checkbox_sound) {
                                                soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F);
                                            }
                                        }

                                    } else {// ?????????
                                        Log.v(TAG, "??????");
                                        if (ringerMode) {// 
                                            Log.v(TAG, "");
                                            if (checkbox_sound) {
                                                soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F);
                                            }
                                            if (checkbox_vibration) {
                                                vibrator.vibrate(1500);
                                            }

                                        } else if (vibrateMode) {// 
                                            Log.v(TAG, "");
                                            if (checkbox_vibration) {
                                                vibrator.vibrate(1500);
                                            }

                                        } else if (silentMode) {// 
                                            Log.v(TAG, "");

                                        }
                                    }

                                }
                                // ?soundPool????
                                new Thread(new Runnable() {

                                    @Override
                                    public void run() {

                                        try {
                                            Thread.sleep(30000);
                                        } catch (InterruptedException e) {
                                        }
                                        //                                 Log.v(TAG, "soundPool.release()");

                                        soundPool.release();

                                    }
                                }).start();
                            }
                        }
                    });

                    // soundPool?????
                    se = soundPool.load(GcmIntentService.this, R.raw.notification_sound, 1);

                    return null;
                }

            }.execute(null, null, null);

            //            sendNotification("??????" + extras.get("INDEX") + "???", intent);
            //                sendNotification("Received: " + extras.toString());
            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}