Search in sources :

Example 21 with IntentFilter

use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.

the class MobileDataStateTracker method startMonitoring.

/**
     * Begin monitoring data connectivity.
     *
     * @param context is the current Android context
     * @param target is the Hander to which to return the events.
     */
public void startMonitoring(Context context, Handler target) {
    mTarget = target;
    mContext = context;
    mHandler = new MdstHandler(target.getLooper(), this);
    IntentFilter filter = new IntentFilter();
    filter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
    filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN);
    filter.addAction(TelephonyIntents.ACTION_DATA_CONNECTION_FAILED);
    mContext.registerReceiver(new MobileDataStateReceiver(), filter);
    mMobileDataState = PhoneConstants.DataState.DISCONNECTED;
}
Also used : IntentFilter(android.content.IntentFilter)

Example 22 with IntentFilter

use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.

the class AnalogClock method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (!mAttached) {
        mAttached = true;
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        getContext().registerReceiver(mIntentReceiver, filter, null, mHandler);
    }
    // NOTE: It's safe to do these after registering the receiver since the receiver always runs
    // in the main thread, therefore the receiver can't run before this method returns.
    // The time zone may have changed while the receiver wasn't registered, so update the Time
    mCalendar = new Time();
    // Make sure we update to the current time
    onTimeChanged();
}
Also used : IntentFilter(android.content.IntentFilter) Time(android.text.format.Time)

Example 23 with IntentFilter

use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.

the class ExternalMediaFormatActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_MEDIA_REMOVED);
    filter.addAction(Intent.ACTION_MEDIA_CHECKING);
    filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
    filter.addAction(Intent.ACTION_MEDIA_SHARED);
    registerReceiver(mStorageReceiver, filter);
}
Also used : IntentFilter(android.content.IntentFilter)

Example 24 with IntentFilter

use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.

the class ResolverActivity method onIntentSelected.

protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
    if (alwaysCheck) {
        // Build a reasonable intent filter, based on what matched.
        IntentFilter filter = new IntentFilter();
        if (intent.getAction() != null) {
            filter.addAction(intent.getAction());
        }
        Set<String> categories = intent.getCategories();
        if (categories != null) {
            for (String cat : categories) {
                filter.addCategory(cat);
            }
        }
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK;
        Uri data = intent.getData();
        if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
            String mimeType = intent.resolveType(this);
            if (mimeType != null) {
                try {
                    filter.addDataType(mimeType);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    Log.w("ResolverActivity", e);
                    filter = null;
                }
            }
        }
        if (data != null && data.getScheme() != null) {
            // or "content:" schemes (see IntentFilter for the reason).
            if (cat != IntentFilter.MATCH_CATEGORY_TYPE || (!"file".equals(data.getScheme()) && !"content".equals(data.getScheme()))) {
                filter.addDataScheme(data.getScheme());
                // Look through the resolved filter to determine which part
                // of it matched the original Intent.
                Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
                if (aIt != null) {
                    while (aIt.hasNext()) {
                        IntentFilter.AuthorityEntry a = aIt.next();
                        if (a.match(data) >= 0) {
                            int port = a.getPort();
                            filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null);
                            break;
                        }
                    }
                }
                Iterator<PatternMatcher> pIt = ri.filter.pathsIterator();
                if (pIt != null) {
                    String path = data.getPath();
                    while (path != null && pIt.hasNext()) {
                        PatternMatcher p = pIt.next();
                        if (p.match(path)) {
                            filter.addDataPath(p.getPath(), p.getType());
                            break;
                        }
                    }
                }
            }
        }
        if (filter != null) {
            final int N = mAdapter.mList.size();
            ComponentName[] set = new ComponentName[N];
            int bestMatch = 0;
            for (int i = 0; i < N; i++) {
                ResolveInfo r = mAdapter.mList.get(i).ri;
                set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
                if (r.match > bestMatch)
                    bestMatch = r.match;
            }
            getPackageManager().addPreferredActivity(filter, bestMatch, set, intent.getComponent());
        }
    }
    if (intent != null) {
        startActivity(intent);
    }
}
Also used : IntentFilter(android.content.IntentFilter) Uri(android.net.Uri) ResolveInfo(android.content.pm.ResolveInfo) ComponentName(android.content.ComponentName) PatternMatcher(android.os.PatternMatcher)

Example 25 with IntentFilter

use of android.content.IntentFilter in project android_frameworks_base by ParanoidAndroid.

the class ThemeUtils method registerThemeChangeReceiver.

public static void registerThemeChangeReceiver(final Context context, final BroadcastReceiver receiver) {
    IntentFilter filter = new IntentFilter(ACTION_TMOBILE_THEME_CHANGED);
    try {
        filter.addDataType(DATA_TYPE_TMOBILE_THEME);
        filter.addDataType(DATA_TYPE_TMOBILE_STYLE);
    } catch (IntentFilter.MalformedMimeTypeException e) {
        Log.e(TAG, "Could not add MIME types to filter", e);
    }
    context.registerReceiver(receiver, filter);
}
Also used : IntentFilter(android.content.IntentFilter)

Aggregations

IntentFilter (android.content.IntentFilter)1441 Intent (android.content.Intent)493 Context (android.content.Context)292 BroadcastReceiver (android.content.BroadcastReceiver)274 PendingIntent (android.app.PendingIntent)148 RemoteException (android.os.RemoteException)80 ComponentName (android.content.ComponentName)54 Handler (android.os.Handler)53 View (android.view.View)45 Test (org.junit.Test)41 Uri (android.net.Uri)40 PowerManager (android.os.PowerManager)38 ArrayList (java.util.ArrayList)37 TextView (android.widget.TextView)36 ResolveInfo (android.content.pm.ResolveInfo)30 File (java.io.File)29 Point (android.graphics.Point)28 PackageManager (android.content.pm.PackageManager)27 IOException (java.io.IOException)25 HandlerThread (android.os.HandlerThread)24