use of android.content.BroadcastReceiver in project android by cSploit.
the class UpdateService method setupNotification.
/**
* connect to the notification manager and create a notification builder.
* it also setup the cancellation Intent for get notified when our notification got cancelled.
*/
private void setupNotification() {
// get notification manager
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// get notification builder
mBuilder = new NotificationCompat.Builder(this);
// create a broadcast receiver to get actions
// performed on the notification by the user
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action == null)
return;
// user cancelled our notification
if (action.equals(NOTIFICATION_CANCELLED)) {
mRunning = false;
}
}
};
// register our receiver
registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED));
// set common notification actions
mBuilder.setDeleteIntent(PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0));
mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
}
use of android.content.BroadcastReceiver in project android by cSploit.
the class MultiAttackService method setupNotification.
private void setupNotification() {
// get notification manager
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// get notification builder
mBuilder = new NotificationCompat.Builder(this);
// create a broadcast receiver to get actions
// performed on the notification by the user
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Logger.debug("received action: " + action);
if (action == null)
return;
// user cancelled our notification
if (action.equals(NOTIFICATION_CANCELLED)) {
mRunning = false;
stopSelf();
}
}
};
mContentIntent = null;
// register our receiver
registerReceiver(mReceiver, new IntentFilter(NOTIFICATION_CANCELLED));
// set common notification actions
mBuilder.setDeleteIntent(PendingIntent.getBroadcast(this, CANCEL_CODE, new Intent(NOTIFICATION_CANCELLED), 0));
mBuilder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
}
use of android.content.BroadcastReceiver in project qksms by moezbhatti.
the class Transaction method sendMMS.
private void sendMMS(final byte[] bytesToSend) {
revokeWifi(true);
// enable mms connection to mobile data
mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
int result = beginMmsConnectivity();
if (LOCAL_LOGV)
Log.v(TAG, "result of connectivity: " + result + " ");
if (result != 0) {
// if mms feature is not already running (most likely isn't...) then register a receiver and wait for it to be active
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context1, Intent intent) {
String action = intent.getAction();
if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
return;
}
@SuppressWarnings("deprecation") NetworkInfo mNetworkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
if ((mNetworkInfo == null) || (mNetworkInfo.getType() != ConnectivityManager.TYPE_MOBILE)) {
return;
}
if (!mNetworkInfo.isConnected()) {
return;
} else {
// ready to send the message now
if (LOCAL_LOGV)
Log.v(TAG, "sending through broadcast receiver");
alreadySending = true;
sendData(bytesToSend);
context.unregisterReceiver(this);
}
}
};
context.registerReceiver(receiver, filter);
try {
Looper.prepare();
} catch (Exception e) {
// Already on UI thread probably
}
// try sending after 3 seconds anyways if for some reason the receiver doesn't work
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!alreadySending) {
try {
if (LOCAL_LOGV)
Log.v(TAG, "sending through handler");
context.unregisterReceiver(receiver);
} catch (Exception e) {
}
sendData(bytesToSend);
}
}
}, 7000);
} else {
// mms connection already active, so send the message
if (LOCAL_LOGV)
Log.v(TAG, "sending right away, already ready");
sendData(bytesToSend);
}
}
use of android.content.BroadcastReceiver in project k-9 by k9mail.
the class MessageListFragment method createCacheBroadcastReceiver.
private void createCacheBroadcastReceiver(Context appContext) {
localBroadcastManager = LocalBroadcastManager.getInstance(appContext);
cacheBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
adapter.notifyDataSetChanged();
}
};
cacheIntentFilter = new IntentFilter(EmailProviderCache.ACTION_CACHE_UPDATED);
}
use of android.content.BroadcastReceiver in project SmartAndroidSource by jaychou2012.
the class SystemInfo method getBatteryLevel.
/**
* Get the device's BatteryLevel
*
* @param callback
* the device's BatteryLevel
*/
public void getBatteryLevel(final GlobalCallback callback) {
final String[] batteryLevel = { "0", "0" };
BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
context.unregisterReceiver(this);
// getCurrentBattery
int rawlevel = intent.getIntExtra("level", -1);
int scale = intent.getIntExtra("scale", -1);
// getAllBattery
int level = -1;
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale;
}
batteryLevel[0] = level + "%";
Log.i("info", batteryLevel[0]);
callback.data_result(batteryLevel[0]);
}
};
IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
context.registerReceiver(batteryLevelReceiver, batteryLevelFilter);
}
Aggregations