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);
}
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();
}
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));
}
}
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));
}
}
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<>();
}
Aggregations