Android Binder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Binder class.

This code example shows how to use the following methods:
import android.content.Intent; 
import android.os.Binder; 
import android.os.IBinder; 
 
public class FakeCoreService extends Service { 
    final Binder mBinder = new Binder(); 
 
    @Override 
    public IBinder onBind(Intent intent) { 
        return mBinder; 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:addService
    @SmallTest 
	public void testAddService() { 
        try { 
            // The security in the service manager is that you can't replace 
            // a service that is already published. 
            Binder binder = new Binder();
            ServiceManager.addService("activity", binder);
            fail("ServiceManager.addService did not throw SecurityException as"
                    + " expected"); 
        } catch (SecurityException e) {
            // expected 
        } 
	} 
 
    @SmallTest 
    public void testSetPermissionController() { 
        try { 
            IPermissionController pc = new IPermissionController.Stub() {
                public boolean checkPermission(java.lang.String permission, int pid, int uid) {
                    return true; 
8
CodeRank
This code example shows how to use the following methods:
import android.os.IBinder; 
import android.os.UserHandle; 
import android.widget.Toast; 
 
public class SingleUserService extends Service {
    Binder mBinder = new Binder();
 
    @Override 
    public void onCreate() { 
        super.onCreate(); 
        Toast.makeText(this,
                "Service created as user " + UserHandle.myUserId(), 
                Toast.LENGTH_LONG).show();
    } 
 
    @Override 
    public IBinder onBind(Intent intent) {
        return mBinder;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
import android.os.IBinder; 
import android.os.UserHandle; 
import android.widget.Toast; 
 
public class ServiceUserTarget extends Service {
    Binder mBinder = new Binder();
 
    @Override 
    public void onCreate() { 
        super.onCreate(); 
        Toast.makeText(this,
                "Service created as user " + UserHandle.myUserId(), 
                Toast.LENGTH_LONG).show();
    } 
 
    @Override 
    public IBinder onBind(Intent intent) {
        return mBinder;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
     *   {@link android.Manifest.permission#VIBRATE} 
     * @throws RemoteException 
     */ 
    public void testVibrate() throws RemoteException { 
        try { 
            mVibratorService.vibrate(Process.myUid(), null, 2000, new Binder());
            fail("vibrate did not throw SecurityException as expected");
        } catch (SecurityException e) {
            // expected 
        } 
    } 
 
    /** 
     * Test that calling {@link android.os.IVibratorService#vibratePattern(long[], 
     * int, android.os.IBinder)} requires permissions. 
     * <p>Tests permission: 
     *   {@link android.Manifest.permission#VIBRATE} 
     * @throws RemoteException 
     */ 
    public void testVibratePattern() throws RemoteException { 
7
CodeRank
This code example shows how to use the following methods:addService
    @SmallTest 
	public void testAddService() { 
        try { 
            // The security in the service manager is that you can't replace 
            // a service that is already published. 
            Binder binder = new Binder();
            ServiceManager.addService("activity", binder);
            fail("ServiceManager.addService did not throw SecurityException as"
                    + " expected"); 
        } catch (SecurityException e) {
            // expected 
        } 
	} 
 
    @SmallTest 
    public void testSetPermissionController() { 
        try { 
            IPermissionController pc = new IPermissionController.Stub() {
                public boolean checkPermission(java.lang.String permission, int pid, int uid) {
                    return true; 
7
CodeRank
This code example shows how to use the following methods:
 
    public static class Foo implements IInterface {
 
        @Override 
        public IBinder asBinder() {
            return new Binder();
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:
    public static final String EXTRA_MIFARE_BLOCK =
        "com.android.nfc_extras.extra.MIFARE_BLOCK"; 
 
    NfcExecutionEnvironment(NfcAdapterExtras extras) {
        mExtras = extras;
        mToken = new Binder();
    } 
 
    /** 
     * Open the NFC Execution Environment on its contact interface. 
     * 
     * <p>Opening a channel to the the secure element may fail 
     * for a number of reasons: 
     * <ul> 
     * <li>NFC must be enabled for the connection to the SE to be opened. 
     * If it is disabled at the time of this call, an {@link EeNfcDisabledException} 
     * is thrown. 
     * 
     * <li>Only one process may open the secure element at a time. Additionally, 
     * this method is not reentrant. If the secure element is already opened, 
7
CodeRank
This code example shows how to use the following methods:
        } 
	}     
 
    @SmallTest 
    public void testDISABLE_KEYGUARD() { 
        Binder token = new Binder();
        try { 
            mWm.disableKeyguard(token, "foo");
            fail("IWindowManager.disableKeyguard did not throw SecurityException as"
                    + " expected"); 
        } catch (SecurityException e) {
            // expected 
        } catch (RemoteException e) {
            fail("Unexpected remote exception");
        } 
         
        try { 
            mWm.reenableKeyguard(token);
            fail("IWindowManager.reenableKeyguard did not throw SecurityException as"
                    + " expected"); 
6
CodeRank
This code example shows how to use the following methods:
import android.content.Intent; 
import android.os.Binder; 
import android.os.IBinder; 
 
public class FakeCoreService extends Service { 
    final Binder mBinder = new Binder(); 
 
    @Override 
    public IBinder onBind(Intent intent) { 
        return mBinder; 
    } 
} 
6
CodeRank

Related Android Binder Questions & Answers:

See Code Examples for Android Binder Methods: