Search in sources :

Example 26 with IntentFilter

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

the class ViewFlipper method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    // Listen for broadcasts related to user-presence
    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);
    getContext().registerReceiver(mReceiver, filter);
    if (mAutoStart) {
        // Automatically start when requested
        startFlipping();
    }
}
Also used : IntentFilter(android.content.IntentFilter)

Example 27 with IntentFilter

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

the class LocalReceiver method onReceive.

public void onReceive(Context context, Intent intent) {
    String resultString = LaunchpadActivity.RECEIVER_LOCAL;
    if (BroadcastTest.BROADCAST_FAIL_REGISTER.equals(intent.getAction())) {
        resultString = "Successfully registered, but expected it to fail";
        try {
            context.registerReceiver(this, new IntentFilter("foo.bar"));
            context.unregisterReceiver(this);
        } catch (ReceiverCallNotAllowedException e) {
            //resultString = "This is the correct behavior but not yet implemented";
            resultString = LaunchpadActivity.RECEIVER_LOCAL;
        }
    } else if (BroadcastTest.BROADCAST_FAIL_BIND.equals(intent.getAction())) {
        resultString = "Successfully bound to service, but expected it to fail";
        try {
            ServiceConnection sc = new ServiceConnection() {

                public void onServiceConnected(ComponentName name, IBinder service) {
                }

                public void onServiceDisconnected(ComponentName name) {
                }
            };
            context.bindService(new Intent(context, LocalService.class), sc, 0);
            context.unbindService(sc);
        } catch (ReceiverCallNotAllowedException e) {
            //resultString = "This is the correct behavior but not yet implemented";
            resultString = LaunchpadActivity.RECEIVER_LOCAL;
        }
    } else if (LaunchpadActivity.BROADCAST_REPEAT.equals(intent.getAction())) {
        Intent newIntent = new Intent(intent);
        newIntent.setAction(LaunchpadActivity.BROADCAST_LOCAL);
        context.sendOrderedBroadcast(newIntent, null);
    }
    try {
        IBinder caller = intent.getIBinderExtra("caller");
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(LaunchpadActivity.LAUNCH);
        data.writeString(resultString);
        caller.transact(LaunchpadActivity.GOT_RECEIVE_TRANSACTION, data, null, 0);
        data.recycle();
    } catch (RemoteException ex) {
    }
}
Also used : ReceiverCallNotAllowedException(android.content.ReceiverCallNotAllowedException) IntentFilter(android.content.IntentFilter) ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Parcel(android.os.Parcel) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RemoteException(android.os.RemoteException)

Example 28 with IntentFilter

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

the class IntentSenderTest method testRegisteredReceivePermissionGranted.

public void testRegisteredReceivePermissionGranted() throws Exception {
    setExpectedReceivers(new String[] { RECEIVER_REG });
    registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_GRANTED);
    addIntermediate("after-register");
    PendingIntent is = PendingIntent.getBroadcast(getContext(), 0, makeBroadcastIntent(BROADCAST_REGISTERED), 0);
    is.send();
    waitForResultOrThrow(BROADCAST_TIMEOUT);
    is.cancel();
}
Also used : IntentFilter(android.content.IntentFilter) PendingIntent(android.app.PendingIntent)

Example 29 with IntentFilter

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

the class IntentSenderTest method testRegisteredReceivePermissionDenied.

public void testRegisteredReceivePermissionDenied() throws Exception {
    final Intent intent = makeBroadcastIntent(BROADCAST_REGISTERED);
    setExpectedReceivers(new String[] { RECEIVER_RESULTS });
    registerMyReceiver(new IntentFilter(BROADCAST_REGISTERED), PERMISSION_DENIED);
    addIntermediate("after-register");
    PendingIntent.OnFinished finish = new PendingIntent.OnFinished() {

        public void onSendFinished(PendingIntent pi, Intent intent, int resultCode, String resultData, Bundle resultExtras) {
            gotReceive(RECEIVER_RESULTS, intent);
        }
    };
    PendingIntent is = PendingIntent.getBroadcast(getContext(), 0, intent, 0);
    is.send(Activity.RESULT_CANCELED, finish, null);
    waitForResultOrThrow(BROADCAST_TIMEOUT);
    is.cancel();
}
Also used : IntentFilter(android.content.IntentFilter) Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 30 with IntentFilter

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

the class AppCacheTest method testFreeStorage.

// TODO: flaky test, omit from LargeTest for now
//@LargeTest
public void testFreeStorage() throws Exception {
    boolean TRACKING = true;
    StatFs st = new StatFs("/data");
    long blks1 = getFreeStorageBlks(st);
    if (localLOGV || TRACKING)
        Log.i(TAG, "Available free blocks=" + blks1);
    long availableMem = getFreeStorageSize(st);
    File cacheDir = mContext.getCacheDir();
    assertNotNull(cacheDir);
    createTestFiles1(cacheDir, "testtmpdir", 5);
    long blks2 = getFreeStorageBlks(st);
    if (localLOGV || TRACKING)
        Log.i(TAG, "Available blocks after writing test files in application cache=" + blks2);
    // Create receiver and register it
    FreeStorageReceiver receiver = new FreeStorageReceiver();
    mContext.registerReceiver(receiver, new IntentFilter(FreeStorageReceiver.ACTION_FREE));
    PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, new Intent(FreeStorageReceiver.ACTION_FREE), 0);
    // Invoke PackageManager api
    if (!invokePMFreeStorage(availableMem, receiver, pi)) {
        fail("Could not invoke PackageManager free storage API");
    }
    long blks3 = getFreeStorageBlks(st);
    if (localLOGV || TRACKING)
        Log.i(TAG, "Available blocks after freeing cache" + blks3);
    assertEquals(receiver.getResultCode(), 1);
    mContext.unregisterReceiver(receiver);
    // Verify result  
    verifyTestFiles1(cacheDir, "testtmpdir", 5);
}
Also used : IntentFilter(android.content.IntentFilter) StatFs(android.os.StatFs) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) File(java.io.File)

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