Search in sources :

Example 11 with HandlerThread

use of android.os.HandlerThread in project remusic by aa112901.

the class MediaService method onCreate.

@Override
public void onCreate() {
    if (D)
        Log.d(TAG, "Creating service");
    super.onCreate();
    mGetUrlThread.start();
    mLrcThread.start();
    mProxy = new MediaPlayerProxy(this);
    mProxy.init();
    mProxy.start();
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);
    mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();
    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setUpMediaSession();
    }
    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();
    registerExternalStorageListener();
    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);
    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    filter.addAction(TRY_GET_TRACKINFO);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(LOCK_SCREEN);
    filter.addAction(SEND_PROGRESS);
    filter.addAction(SETQUEUE);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);
    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);
    final Intent shutdownIntent = new Intent(this, MediaService.class);
    shutdownIntent.setAction(SHUTDOWN);
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);
    scheduleDelayedShutdown();
    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}
Also used : PowerManager(android.os.PowerManager) IntentFilter(android.content.IntentFilter) MediaPlayerProxy(com.wm.remusic.proxy.utils.MediaPlayerProxy) HandlerThread(android.os.HandlerThread) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 12 with HandlerThread

use of android.os.HandlerThread in project zxing-android-embedded by journeyapps.

the class CameraThread method checkRunning.

private void checkRunning() {
    synchronized (LOCK) {
        if (this.handler == null) {
            if (openCount <= 0) {
                throw new IllegalStateException("CameraThread is not open");
            }
            this.thread = new HandlerThread("CameraThread");
            this.thread.start();
            this.handler = new Handler(thread.getLooper());
        }
    }
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler)

Example 13 with HandlerThread

use of android.os.HandlerThread in project Klyph by jonathangerbaud.

the class FriendRequestService method onCreate.

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, new WeakReference<Service>(this));
}
Also used : HandlerThread(android.os.HandlerThread) WeakReference(java.lang.ref.WeakReference)

Example 14 with HandlerThread

use of android.os.HandlerThread in project Klyph by jonathangerbaud.

the class NotificationService method onCreate.

@Override
public void onCreate() {
    // Why initialize device values ?
    // Because we need the density to calculate image size
    // In notification request
    KlyphDevice.initDeviceValues(this);
    HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, new WeakReference<Service>(this));
}
Also used : HandlerThread(android.os.HandlerThread) WeakReference(java.lang.ref.WeakReference)

Example 15 with HandlerThread

use of android.os.HandlerThread in project Klyph by jonathangerbaud.

the class UploadPhotoService method onCreate.

@Override
public void onCreate() {
    HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper, new WeakReference<Service>(this));
}
Also used : HandlerThread(android.os.HandlerThread) WeakReference(java.lang.ref.WeakReference)

Aggregations

HandlerThread (android.os.HandlerThread)292 Handler (android.os.Handler)128 Message (android.os.Message)26 IntentFilter (android.content.IntentFilter)24 Intent (android.content.Intent)22 Context (android.content.Context)20 Test (org.junit.Test)20 PowerManager (android.os.PowerManager)15 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 View (android.view.View)14 PendingIntent (android.app.PendingIntent)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Looper (android.os.Looper)11 RemoteException (android.os.RemoteException)11 MediaFormat (android.media.MediaFormat)10 Pair (android.util.Pair)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Uri (android.net.Uri)8 IOException (java.io.IOException)8