Search in sources :

Example 91 with BroadcastReceiver

use of android.content.BroadcastReceiver in project chromeview by pwnall.

the class AudioManagerAndroid method registerHeadsetReceiver.

@CalledByNative
public void registerHeadsetReceiver() {
    if (mReceiver != null) {
        return;
    }
    mOriginalSpeakerStatus = mAudioManager.isSpeakerphoneOn();
    IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    mReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
                try {
                    mAudioManager.setSpeakerphoneOn(intent.getIntExtra("state", 0) == 0);
                } catch (SecurityException e) {
                    Log.e(TAG, "setMode exception: " + e.getMessage());
                    logDeviceInfo();
                }
            }
        }
    };
    mContext.registerReceiver(mReceiver, filter);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) CalledByNative(org.chromium.base.CalledByNative)

Example 92 with BroadcastReceiver

use of android.content.BroadcastReceiver in project weiciyuan by qii.

the class JBInboxNotification method get.

public Notification get() {
    Notification.Builder builder = new Notification.Builder(context).setTicker(NotificationUtility.getTicker(unreadBean, null, null, null)).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
    builder.setContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
    if (NotificationUtility.getCount(unreadBean) > 1) {
        builder.setNumber(NotificationUtility.getCount(unreadBean));
    }
    if (clearNotificationEventReceiver != null) {
        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
        JBInboxNotification.clearNotificationEventReceiver = null;
    }
    clearNotificationEventReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionStatusUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
                        new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
                    } catch (WeiboException ignored) {
                    } finally {
                        GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
                        JBInboxNotification.clearNotificationEventReceiver = null;
                    }
                }
            }).start();
        }
    };
    IntentFilter intentFilter = new IntentFilter("org.qii.weiciyuan.Notification.unread");
    GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);
    Intent broadcastIntent = new Intent("org.qii.weiciyuan.Notification.unread");
    PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);
    Notification.InboxStyle inboxStyle = new Notification.InboxStyle(builder);
    inboxStyle.setBigContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
    if (comment != null) {
        for (CommentBean c : comment.getItemList()) {
            inboxStyle.addLine(c.getUser().getScreen_name() + ":" + c.getText());
        }
    }
    if (repost != null) {
        for (MessageBean m : repost.getItemList()) {
            inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
        }
    }
    if (mentionCommentsResult != null) {
        for (CommentBean m : mentionCommentsResult.getItemList()) {
            inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
        }
    }
    inboxStyle.setSummaryText(accountBean.getUsernick());
    builder.setStyle(inboxStyle);
    Utility.configVibrateLedRingTone(builder);
    return builder.build();
}
Also used : Context(android.content.Context) GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver) Notification(android.app.Notification) ClearUnreadDao(org.qii.weiciyuan.dao.unread.ClearUnreadDao) WeiboException(org.qii.weiciyuan.support.error.WeiboException) PendingIntent(android.app.PendingIntent)

Example 93 with BroadcastReceiver

use of android.content.BroadcastReceiver in project platform_frameworks_base by android.

the class BluetoothTestUtils method discoverable.

/**
     * Puts the local device into discoverable mode and checks to make sure that the local device
     * is in discoverable mode and that the correct actions were broadcast.
     *
     * @param adapter The BT adapter.
     */
public void discoverable(BluetoothAdapter adapter) {
    if (!adapter.isEnabled()) {
        fail("discoverable() bluetooth not enabled");
    }
    int scanMode = adapter.getScanMode();
    if (scanMode != BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
        return;
    }
    final Semaphore completionSemaphore = new Semaphore(0);
    final BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (!BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(action)) {
                return;
            }
            final int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
            if (mode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
                completionSemaphore.release();
            }
        }
    };
    final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
    mContext.registerReceiver(receiver, filter);
    assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
    boolean success = false;
    try {
        success = completionSemaphore.tryAcquire(DISCOVERABLE_UNDISCOVERABLE_TIMEOUT, TimeUnit.MILLISECONDS);
        writeOutput(String.format("discoverable() completed in 0 ms"));
    } catch (final InterruptedException e) {
    // This should never happen but just in case it does, the test will fail anyway.
    }
    mContext.unregisterReceiver(receiver);
    if (!success) {
        fail(String.format("discoverable() timeout: scanMode=%d (expected %d)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Semaphore(java.util.concurrent.Semaphore) BroadcastReceiver(android.content.BroadcastReceiver)

Example 94 with BroadcastReceiver

use of android.content.BroadcastReceiver in project platform_frameworks_base by android.

the class BluetoothTestUtils method enable.

/**
     * Enables Bluetooth and checks to make sure that Bluetooth was turned on and that the correct
     * actions were broadcast.
     *
     * @param adapter The BT adapter.
     */
public void enable(BluetoothAdapter adapter) {
    writeOutput("Enabling Bluetooth adapter.");
    assertFalse(adapter.isEnabled());
    int btState = adapter.getState();
    final Semaphore completionSemaphore = new Semaphore(0);
    final BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                return;
            }
            final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
            if (state == BluetoothAdapter.STATE_ON) {
                completionSemaphore.release();
            }
        }
    };
    final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    mContext.registerReceiver(receiver, filter);
    assertTrue(adapter.enable());
    boolean success = false;
    try {
        success = completionSemaphore.tryAcquire(ENABLE_DISABLE_TIMEOUT, TimeUnit.MILLISECONDS);
        writeOutput(String.format("enable() completed in 0 ms"));
    } catch (final InterruptedException e) {
    // This should never happen but just in case it does, the test will fail anyway.
    }
    mContext.unregisterReceiver(receiver);
    if (!success) {
        fail(String.format("enable() timeout: state=%d (expected %d)", btState, BluetoothAdapter.STATE_ON));
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Semaphore(java.util.concurrent.Semaphore) BroadcastReceiver(android.content.BroadcastReceiver)

Example 95 with BroadcastReceiver

use of android.content.BroadcastReceiver in project platform_frameworks_base by android.

the class UserManagerTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mUserManager = UserManager.get(getContext());
    IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
    getContext().registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            synchronized (mUserLock) {
                mUserLock.notifyAll();
            }
        }
    }, filter);
    removeExistingUsers();
    usersToRemove = new ArrayList<>();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)637 Intent (android.content.Intent)564 Context (android.content.Context)493 IntentFilter (android.content.IntentFilter)441 PendingIntent (android.app.PendingIntent)120 Test (org.junit.Test)109 ArrayList (java.util.ArrayList)34 RemoteException (android.os.RemoteException)29 Bundle (android.os.Bundle)24 IOException (java.io.IOException)23 Point (android.graphics.Point)20 Semaphore (java.util.concurrent.Semaphore)20 View (android.view.View)19 Handler (android.os.Handler)18 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)17 ComponentName (android.content.ComponentName)16 TextView (android.widget.TextView)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14