Search in sources :

Example 1 with BroadcastReceiver

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));
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 2 with BroadcastReceiver

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));
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 3 with BroadcastReceiver

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);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) NetworkInfo(android.net.NetworkInfo) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) MmsException(com.google.android.mms.MmsException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with BroadcastReceiver

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);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 5 with BroadcastReceiver

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);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)620 Intent (android.content.Intent)547 Context (android.content.Context)481 IntentFilter (android.content.IntentFilter)427 PendingIntent (android.app.PendingIntent)116 Test (org.junit.Test)92 ArrayList (java.util.ArrayList)32 RemoteException (android.os.RemoteException)29 IOException (java.io.IOException)23 Bundle (android.os.Bundle)22 Point (android.graphics.Point)20 Semaphore (java.util.concurrent.Semaphore)20 View (android.view.View)19 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)17 TextView (android.widget.TextView)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14 ComponentName (android.content.ComponentName)13 DialogInterface (android.content.DialogInterface)13