コード例 #1
0
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   if (!ReceiverService.running()) {
     startReceiving();
   }
   return Service.START_STICKY;
 }
コード例 #2
0
  private static void playText(String text, final ReceiverService service) {
    try {
      URL url =
          new URL(
              "http://translate.google.com/translate_tts?ie=UTF-8&tl=ru&q="
                  + URLEncoder.encode(text, "UTF-8"));
      File file = FileUtils.saveTempFile(url);
      service.setMaxVolume();
      MediaPlayer player = MediaPlayer.create(service, Uri.fromFile(file));
      player.start();
      player.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {

            public void onCompletion(MediaPlayer mp) {
              service.restoreVolume();
            }
          });

      Log.i(TAG, "Player playing");
    } catch (FileNotFoundException ex) {
      Log.e(TAG, "", ex);
    } catch (IOException ex) {
      Log.e(TAG, "", ex);
    }
  }
コード例 #3
0
 @Override
 public void onDestroy() {
   Log.i(TAG, "onDestroy()");
   if (ReceiverService.running()) {
     stopReceiving();
   }
   toast("Message receiver stopped");
   super.onDestroy();
 }
コード例 #4
0
 public void stop() {
   if (destroyed) {
     return;
   }
   destroyed = true;
   count--;
   if (count == 0) {
     stopServicesMDNS();
     service.stopSelf();
   }
   thread.interrupt();
   try {
     serverSocket.close();
   } catch (IOException ex) {
     Log.e(TAG, "", ex);
   }
   Log.i(TAG, "Server " + addr.getHostName() + " stopped");
 }