List of usage examples for android.net.wifi WifiManager WIFI_MODE_FULL
int WIFI_MODE_FULL
To view the source code for android.net.wifi WifiManager WIFI_MODE_FULL.
Click Source Link
From source file:com.qweex.callisto.podcast.DownloadTask.java
@Override protected Boolean doInBackground(String... params) { String TAG = StaticBlob.TAG(); boolean isVideo; Cursor current;/*from ww w .j a v a 2 s. co m*/ long id = 0, identity = 0; Log.e(TAG, "Preparing to start: " + StaticBlob.databaseConnector.getActiveDownloads().getCount() + " downloads"); boolean canceled = false; while (StaticBlob.databaseConnector.getActiveDownloads().getCount() > 0) { if (isCancelled()) //Checks to see if it has been canceled by somewhere else { mNotificationManager.cancel(NOTIFICATION_ID); return false; } try { Cursor c = StaticBlob.databaseConnector.getActiveDownloads(); c.moveToFirst(); id = c.getLong(c.getColumnIndex("_id")); identity = c.getLong(c.getColumnIndex("identity")); isVideo = c.getInt(c.getColumnIndex("video")) > 0; current = StaticBlob.databaseConnector.getOneEpisode(identity); current.moveToFirst(); //Get info AudLink = current.getString(current.getColumnIndex("mp3link")); VidLink = current.getString(current.getColumnIndex("vidlink")); AudSize = current.getLong(current.getColumnIndex("mp3size")); VidSize = current.getLong(current.getColumnIndex("vidsize")); Title = current.getString(current.getColumnIndex("title")); Date = current.getString(current.getColumnIndex("date")); Show = current.getString(current.getColumnIndex("show")); Date = StaticBlob.sdfFile.format(StaticBlob.sdfRaw.parse(Date)); //Getting target Target = new File(StaticBlob.storage_path + File.separator + Show); Target.mkdirs(); if (Title.indexOf("|") > 0) Title = Title.substring(0, Title.indexOf("|")); Title = Title.trim(); AudFile = new File(Target, Date + "__" + StaticBlob.makeFileFriendly(Title) + EpisodeDesc.getExtension(AudLink)); if (VidLink != null) VidFile = new File(Target, Date + "__" + StaticBlob.makeFileFriendly(Title) + EpisodeDesc.getExtension(VidLink)); Target = isVideo ? VidFile : AudFile; //Prepare the HTTP Log.i(TAG, "Path: " + Target.getPath()); URL url = new URL(isVideo ? VidLink : AudLink); Log.i(TAG, "Starting download: " + url.toString()); Log.i(TAG, "Opening the connection..."); HttpURLConnection ucon = (HttpURLConnection) url.openConnection(); String lastModified = ucon.getHeaderField("Last-Modified"); ucon = (HttpURLConnection) url.openConnection(); if (Target.exists()) { ucon.setRequestProperty("Range", "bytes=" + Target.length() + "-"); ucon.setRequestProperty("If-Range", lastModified); } ucon.setReadTimeout(TIMEOUT_CONNECTION); ucon.setConnectTimeout(TIMEOUT_SOCKET); ucon.connect(); //Notification mBuilder.setProgress(100, 0, true) .setContentTitle(this.context.getResources().getString(R.string.downloading) + " " + StaticBlob.current_download + " " + this.context.getResources().getString(R.string.of) + " " + downloading_count) .setContentText(Show + ": " + Title); // Displays the progress bar for the first time. mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); //Actually do the DLing InputStream is = ucon.getInputStream(); TotalSize = ucon.getContentLength() + Target.length(); BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5); FileOutputStream outStream; byte buff[]; Log.i(TAG, "mmk skipping the downloaded portion..." + Target.length() + " of " + TotalSize); if (Target.exists()) //Append if it exists outStream = new FileOutputStream(Target, true); else outStream = new FileOutputStream(Target); buff = new byte[5 * 1024]; Log.i(TAG, "Getting content length (size)"); int len = 0; long downloadedSize = Target.length(), percentDone = 0; //SPEED_COUNT == the number of times through the buffer loop to go through before updating the speed // currentDownloadLoopIndex == ??? // lastTime == The time that the last speed was calculated at // all_spds == All speeds tabulated thus far from currentDownloadLoopIndex to SPEED_COUNT // avg_speed == the average speed when SPEED_COUNT is reached int SPEED_COUNT = 200, currentDownloadLoopIndex = 0; long lastTime = (new java.util.Date()).getTime(), all_spds = 0; double avg_speed = 0; DecimalFormat df = new DecimalFormat("#.##"); //Wifi lock WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (DownloadList.Download_wifiLock == null) DownloadList.Download_wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "Callisto_download"); if (!DownloadList.Download_wifiLock.isHeld()) DownloadList.Download_wifiLock.acquire(); Log.i(TAG, "FINALLY starting the download"); inner_failures = 0; //-----------------Here is where the actual downloading happens---------------- while (len != -1) { Cursor active = StaticBlob.databaseConnector.getActiveDownloads(); if (StaticBlob.databaseConnector.getActiveDownloads().getCount() == 0) canceled = true; else { active.moveToFirst(); canceled = active.getLong(active.getColumnIndex("identity")) != identity; } if (canceled) { Log.i(TAG, "Download has been canceled, deleting."); Target.delete(); break; } if (isCancelled()) { mNotificationManager.cancel(NOTIFICATION_ID); return false; } try { len = inStream.read(buff); if (len == -1) break; outStream.write(buff, 0, len); downloadedSize += len; percentDone = downloadedSize * 100; percentDone /= TotalSize; //Add to the average speed long temp_spd = 0; long time_diff = ((new java.util.Date()).getTime() - lastTime); if (time_diff > 0) { temp_spd = len * 100 / time_diff; currentDownloadLoopIndex++; all_spds += temp_spd; lastTime = (new java.util.Date()).getTime(); } } catch (IOException e) { Log.e(TAG + ":IOException", "IO is a moon - " + inner_failures); inner_failures++; if (inner_failures == INNER_LIMIT) break; try { Thread.sleep(500); } catch (InterruptedException e1) { } //Add failure to average currentDownloadLoopIndex++; lastTime = (new java.util.Date()).getTime(); } catch (Exception e) { Log.e(TAG + ":??Exception", e.getClass() + " : " + e.getMessage()); try { Thread.sleep(500); } catch (InterruptedException e1) { } //Add failure to average currentDownloadLoopIndex++; lastTime = (new java.util.Date()).getTime(); } //If the time is right, get the average if (currentDownloadLoopIndex >= SPEED_COUNT) { avg_speed = all_spds * 1.0 / currentDownloadLoopIndex / 100; all_spds = 0; currentDownloadLoopIndex = 0; if (DownloadList.thisInstance != null) { DownloadList.thisInstance.runOnUiThread( DownloadList.thisInstance.new DownloadProgressUpdater((int) (TotalSize / 1000), (int) (downloadedSize / 1000))); } mBuilder.setProgress((int) (TotalSize / 1000), (int) (downloadedSize / 1000), false) .setContentTitle(this.context.getResources().getString(R.string.downloading) + " " + StaticBlob.current_download + " " + this.context.getResources().getString(R.string.of) + " " + downloading_count + " - " + percentDone + "% (" + df.format(avg_speed) + "kb/s)") .setContentText(Show + ": " + Title); // Displays the progress bar for the first time. mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } } // END download of single file outStream.flush(); outStream.close(); inStream.close(); if (inner_failures == INNER_LIMIT) { throw new Exception("Inner exception has passed " + INNER_LIMIT); } Cursor active = StaticBlob.databaseConnector.getActiveDownloads(); if (StaticBlob.databaseConnector.getActiveDownloads().getCount() == 0) canceled = true; else { active.moveToFirst(); canceled = active.getLong(active.getColumnIndex("identity")) != identity; } if (!canceled) { Log.i(TAG, "Trying to finish with " + Target.length() + "==" + TotalSize); if (Target.length() == TotalSize) { StaticBlob.current_download++; Log.i(TAG, (inner_failures < INNER_LIMIT ? "Successfully" : "FAILED") + " downloaded to : " + Target.getPath()); //Move the download from active to completed. StaticBlob.databaseConnector.markDownloadComplete(id); Log.i(TAG, " " + DownloadList.rebuildHeaderThings); if (DownloadList.rebuildHeaderThings != null) DownloadList.rebuildHeaderThings.sendEmptyMessage(0); boolean queue = PreferenceManager.getDefaultSharedPreferences(context) .getBoolean("download_to_queue", false); if (queue) { StaticBlob.databaseConnector.appendToQueue(identity, false, isVideo); StaticBlob.playerInfo.update(context); } //Episode Desc if (EpisodeDesc.currentInstance != null) EpisodeDesc.currentInstance.determineButtons(); //ShowList if (ShowList.thisInstance != null && ShowList.thisInstance.currentDownloadItem != null) { ShowList.thisInstance.runOnUiThread(ShowList.thisInstance.new updateBoldOrItalic(id, ShowList.thisInstance.currentDownloadItem, AudFile, VidFile, AudSize, VidSize)); ShowList.thisInstance.currentDownloadItem = null; } } } else Target.delete(); } catch (ParseException e) { Log.e(TAG + ":ParseException", "Error parsing a date from the SQLite db: "); Log.e(TAG + ":ParseException", Date); Log.e(TAG + ":ParseException", "(This should never happen)."); outer_failures++; e.printStackTrace(); } catch (Exception e) { outer_failures++; Log.e(TAG + ":Exception " + e.getClass(), "[" + outer_failures + "] Msg: " + e.getMessage()); e.printStackTrace(); try { Thread.sleep(1000); } catch (InterruptedException e1) { } } if (outer_failures == OUTER_LIMIT) { boolean quit = false; //if(quit = aDownloads.charAt(1)=='x') // aDownloads = aDownloads.replaceAll("x",""); quit = true; if (DownloadList.rebuildHeaderThings != null) DownloadList.rebuildHeaderThings.sendEmptyMessage(0); failed++; outer_failures = 0; if (quit) break; } } Log.i(TAG, "Finished Downloading"); if (DownloadList.thisInstance != null) DownloadList.thisInstance.updateMenu(); //Wifi lock if (DownloadList.Download_wifiLock != null && DownloadList.Download_wifiLock.isHeld()) DownloadList.Download_wifiLock.release(); //Notification mNotificationManager.cancel(NOTIFICATION_ID); if (downloading_count > 0) { mBuilder.setProgress(100, 0, false) .setContentTitle("Finished downloading " + downloading_count + " files"); if (failed > 0) mBuilder.setContentText(failed + " failed, try them again later"); mBuilder.setAutoCancel(true); mBuilder.setOngoing(false); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); StaticBlob.current_download = 1; downloading_count = 0; } else { StaticBlob.current_download = 1; downloading_count = 0; return false; } return true; }
From source file:com.nd.android.u.square.service.MusicPlaybackService.java
@Override public void onCreate() { Log.i(TAG, "debug: Creating service"); sInstance = this; // Create the Wifi lock (this does not acquire the lock, this just creates it) mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock"); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); // create the Audio Focus Helper, if the Audio Focus feature is available (SDK 8 or above) if (android.os.Build.VERSION.SDK_INT >= 8) mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this); else/*from ww w . j a v a2 s.c om*/ mAudioFocus = AudioFocus.Focused; // no focus feature, so we always "have" audio focus mDummyAlbumArt = BitmapFactory.decodeResource(getResources(), R.drawable.ic_square_notification_music_play); mMediaButtonReceiverComponent = new ComponentName(this, MusicIntentReceiver.class); MusicExecutor.getInstance().getEventBus().register(this); // ? MusicExecutor.getInstance().schedulePlayListUpdate(0L, 10L, TimeUnit.SECONDS); IntentFilter notificationIntentFilter = new IntentFilter(); notificationIntentFilter.addAction(ACTION_STOP); registerReceiver(mNotificationIntentActionReceiver, notificationIntentFilter); }
From source file:eu.chainfire.opendelta.UpdateService.java
@SuppressWarnings("deprecation") @Override// ww w. ja v a 2 s.c o m public void onCreate() { super.onCreate(); config = Config.getInstance(this); wakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock( config.getKeepScreenOn() ? PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP : PowerManager.PARTIAL_WAKE_LOCK, "OpenDelta WakeLock"); wifiLock = ((WifiManager) getSystemService(WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "OpenDelta WifiLock"); handlerThread = new HandlerThread("OpenDelta Service Thread"); handlerThread.start(); handler = new Handler(handlerThread.getLooper()); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); prefs = PreferenceManager.getDefaultSharedPreferences(this); scheduler = new Scheduler(this, this); networkState = new NetworkState(); networkState.start(this, this, prefs.getInt(PREF_AUTO_UPDATE_NETWORKS_NAME, PREF_AUTO_UPDATE_NETWORKS_DEFAULT)); batteryState = new BatteryState(); batteryState.start(this, this, 50, true); screenState = new ScreenState(); screenState.start(this, this); prefs.registerOnSharedPreferenceChangeListener(this); autoState(); }
From source file:com.quran.labs.androidquran.service.AudioService.java
@Override public void onCreate() { Log.i(TAG, "debug: Creating service"); mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "audiolock"); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); // create the Audio Focus Helper, if the Audio Focus feature is available if (android.os.Build.VERSION.SDK_INT >= 8) { mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this); }/*from ww w. ja v a2s . c om*/ // no focus feature, so we always "have" audio focus else { mAudioFocus = AudioFocus.Focused; } mMediaButtonReceiverComponent = new ComponentName(this, AudioIntentReceiver.class); mNotificationName = getString(R.string.app_name); mBroadcastManager = LocalBroadcastManager.getInstance(getApplicationContext()); }
From source file:com.sentaroh.android.SMBExplorer.FileIo.java
@SuppressWarnings("deprecation") @Override/* w w w. ja va 2 s .com*/ public void run() { sendLogMsg("I", "Task has started."); final WakeLock wake_lock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP // | PowerManager.ON_AFTER_RELEASE , "SMBExplorer-ScreenOn"); final WifiLock wifi_lock = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "SMBExplorer-wifi"); if (mGp.fileIoWakeLockRequired) wake_lock.acquire(); if (mGp.fileIoWifiLockRequired) wifi_lock.acquire(); try { if (fileIoArea == null) fileIoArea = new byte[SMB_BUFF_SIZE];//4096*64]; taskBeginTime = System.currentTimeMillis(); waitMediaScanner(true); boolean fileioTaskResultOk = false; for (int i = 0; i < fileioLinkParm.size(); i++) { fileioTaskResultOk = fileOperation(fileioLinkParm.get(i)); if (!fileioTaskResultOk) break; } sendLogMsg("I", "Task was ended. fileioTaskResultOk=" + fileioTaskResultOk + ", fileioThreadCtrl:" + fileioThreadCtrl.toString()); sendLogMsg("I", "Task elapsed time=" + (System.currentTimeMillis() - taskBeginTime)); if (fileioTaskResultOk) { fileioThreadCtrl.setThreadResultSuccess(); sendDebugLogMsg(1, "I", "Task was endeded without error."); } else if (fileioThreadCtrl.isEnabled()) { fileioThreadCtrl.setThreadResultError(); sendLogMsg("W", "Task was ended with error."); } else { fileioThreadCtrl.setThreadResultCancelled(); sendLogMsg("W", "Task was cancelled."); } fileioThreadCtrl.setDisabled(); mediaScanner.disconnect(); waitMediaScanner(false); uiHandler.post(new Runnable() {// UI thread @Override public void run() { notifyEvent.notifyToListener(true, null); } }); } finally { if (wake_lock.isHeld()) wake_lock.release(); if (wifi_lock.isHeld()) wifi_lock.release(); } }
From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java
/** Called when the activity is first created. */ @Override/*from ww w. j a v a 2s. c om*/ public void onCreate(Bundle savedInstanceState) { // StrictMode.enableDefaults(); // setTheme(android.R.style.Theme_Dialog); // setTheme(android.R.style.Theme_Holo_Light); // setTheme(android.R.style.Theme_Light); super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_NO_TITLE); mCurrentLocal = getResources().getConfiguration().locale; setContentView(R.layout.main); mContext = this; mGp = (GlobalParameters) getApplication(); mGp.enableMainUi = true; mGp.uiHandler = new Handler(); mGp.SMBSync_External_Root_Dir = LocalMountPoint.getExternalStorageDir(); startService(new Intent(mContext, SMBSyncService.class)); mDimScreenWakelock = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK // PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP // | PowerManager.ON_AFTER_RELEASE , "SMBSync-ScreenOn"); mWifiLock = ((WifiManager) mContext.getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "SMBSync-wifi"); if (tcService == null) tcService = new ThreadCtrl(); // if (Build.VERSION.SDK_INT>=14) // this.getActionBar().setHomeButtonEnabled(false); if (util == null) util = new SMBSyncUtil(this.getApplicationContext(), "Main", mGp); util.setActivityIsForeground(true); if (ccMenu == null) ccMenu = new CustomContextMenu(getResources(), getSupportFragmentManager()); commonDlg = new CommonDialog(mContext, getSupportFragmentManager()); createTabView(); loadMsgString(); initSettingsParms(); applySettingParms(); initJcifsOption(); checkExternalStorage(); mGp.SMBSync_Internal_Root_Dir = getFilesDir().toString(); util.openLogFile(); initAdapterAndView(); util.addDebugLogMsg(1, "I", "onCreate entered, " + "resartStatus=" + restartStatus + ", isActivityForeground=" + util.isActivityForeground()); getApplVersionName(); if (profMaint == null) profMaint = new ProfileMaintenance(util, this, commonDlg, ccMenu, mGp); SchedulerMain.setTimer(mContext, SCHEDULER_INTENT_SET_TIMER_IF_NOT_SET); }
From source file:com.horizondigital.delta.UpdateService.java
@SuppressWarnings("deprecation") @Override/*from w w w. j a va 2s.co m*/ public void onCreate() { super.onCreate(); Logger.setDebugLogging(getResources().getBoolean(R.bool.debug_output)); property_version = getProperty(getString(R.string.property_version), ""); property_device = getProperty(getString(R.string.property_device), ""); filename_base = String.format(Locale.ENGLISH, getString(R.string.filename_base), property_version); path_base = String.format(Locale.ENGLISH, "%s%s%s%s", Environment.getExternalStorageDirectory().getAbsolutePath(), File.separator, getString(R.string.path_base), File.separator); path_flash_after_update = String.format(Locale.ENGLISH, "%s%s%s", path_base, "FlashAfterUpdate", File.separator); url_base_delta = String.format(Locale.ENGLISH, getString(R.string.url_base_delta), property_device); url_base_update = String.format(Locale.ENGLISH, getString(R.string.url_base_update), property_device); url_base_full = String.format(Locale.ENGLISH, getString(R.string.url_base_full), property_device); apply_signature = getResources().getBoolean(R.bool.apply_signature); Logger.d("property_version: %s", property_version); Logger.d("property_device: %s", property_device); Logger.d("filename_base: %s", filename_base); Logger.d("path_base: %s", path_base); Logger.d("path_flash_after_update: %s", path_flash_after_update); Logger.d("url_base_delta: %s", url_base_delta); Logger.d("url_base_update: %s", url_base_update); Logger.d("url_base_full: %s", url_base_full); config = Config.getInstance(this); wakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock( config.getKeepScreenOn() ? PowerManager.SCREEN_DIM_WAKE_LOCK : PowerManager.PARTIAL_WAKE_LOCK, "CarbonDelta WakeLock"); wifiLock = ((WifiManager) getSystemService(WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "CarbonDelta WifiLock"); handlerThread = new HandlerThread("CarbonDelta Service Thread"); handlerThread.start(); handler = new Handler(handlerThread.getLooper()); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); prefs = PreferenceManager.getDefaultSharedPreferences(this); scheduler = new Scheduler(this, this); networkState = new NetworkState(); networkState.start(this, this, prefs.getInt(PREF_AUTO_UPDATE_NETWORKS_NAME, PREF_AUTO_UPDATE_NETWORKS_DEFAULT)); batteryState = new BatteryState(); batteryState.start(this, this, 50, true); screenState = new ScreenState(); screenState.start(this, this); prefs.registerOnSharedPreferenceChangeListener(this); autoState(); }
From source file:com.kiandastream.musicplayer.MusicService.java
@Override public void onCreate() { Log.i(TAG, "debug: Creating service"); // Create the Wifi lock (this does not acquire the lock, this just creates it) mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock"); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); // Create the retriever and start an asynchronous task that will prepare it. // create the Audio Focus Helper, if the Audio Focus feature is available (SDK 8 or above) }
From source file:syncthing.android.service.SyncthingInstance.java
void acquireWifiLock() { releaseWifiLock(); mWifiLock = mWifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "SyncthingInstance"); mWifiLock.acquire(); }
From source file:github.popeen.dsub.service.DownloadService.java
@Override public void onCreate() { super.onCreate(); final SharedPreferences prefs = Util.getPreferences(this); new Thread(new Runnable() { public void run() { Looper.prepare();/*from w ww.jav a 2 s. co m*/ mediaPlayer = new MediaPlayer(); mediaPlayer.setWakeMode(DownloadService.this, PowerManager.PARTIAL_WAKE_LOCK); // We want to change audio session id's between upgrading Android versions. Upgrading to Android 7.0 is broken (probably updated session id format) audioSessionId = -1; int id = prefs.getInt(Constants.CACHE_AUDIO_SESSION_ID, -1); int versionCode = prefs.getInt(Constants.CACHE_AUDIO_SESSION_VERSION_CODE, -1); if (versionCode == Build.VERSION.SDK_INT && id != -1) { try { audioSessionId = id; mediaPlayer.setAudioSessionId(audioSessionId); } catch (Throwable e) { Log.w(TAG, "Failed to use cached audio session", e); audioSessionId = -1; } } if (audioSessionId == -1) { mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { audioSessionId = mediaPlayer.getAudioSessionId(); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId); editor.putInt(Constants.CACHE_AUDIO_SESSION_VERSION_CODE, Build.VERSION.SDK_INT); editor.commit(); } catch (Throwable t) { // Froyo or lower } } mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mediaPlayer, int what, int more) { handleError(new Exception("MediaPlayer error: " + what + " (" + more + ")")); return false; } }); /*try { Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId); i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(i); } catch(Throwable e) { // Froyo or lower }*/ effectsController = new AudioEffectsController(DownloadService.this, audioSessionId); if (prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) { getEqualizerController(); } mediaPlayerLooper = Looper.myLooper(); mediaPlayerHandler = new Handler(mediaPlayerLooper); if (runListenersOnInit) { onSongsChanged(); onSongProgress(); onStateUpdate(); } Looper.loop(); } }, "DownloadService").start(); Util.registerMediaButtonEventReceiver(this); audioNoisyReceiver = new AudioNoisyReceiver(); registerReceiver(audioNoisyReceiver, audioNoisyIntent); if (mRemoteControl == null) { // Use the remote control APIs (if available) to set the playback state mRemoteControl = RemoteControlClientBase.createInstance(); ComponentName mediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mRemoteControl.register(this, mediaButtonReceiverComponent); } PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); wakeLock.setReferenceCounted(false); WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "downloadServiceLock"); try { timerDuration = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "5")); } catch (Throwable e) { timerDuration = 5; } sleepTimer = null; keepScreenOn = prefs.getBoolean(Constants.PREFERENCES_KEY_KEEP_SCREEN_ON, false); mediaRouter = new MediaRouteManager(this); instance = this; shufflePlayBuffer = new ShufflePlayBuffer(this); artistRadioBuffer = new ArtistRadioBuffer(this); lifecycleSupport.onCreate(); if (Build.VERSION.SDK_INT >= 26) { Notifications.shutGoogleUpNotification(this); } }