Java Code Examples for android.os.IBinder.transact()

The following are Jave code examples for showing how to use transact() of the android.os.IBinder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: OpenUDID_manager.java   Source Code and License Vote up 6 votes
@Override
	public void onServiceConnected(ComponentName className, IBinder service) {
//Get the OpenUDID from the remote service
try {
	//Send a random number to the service
	android.os.Parcel data = android.os.Parcel.obtain(); 
	data.writeInt(mRandom.nextInt());
	android.os.Parcel reply = android.os.Parcel.obtain(); 
	service.transact(1, android.os.Parcel.obtain(), reply, 0);
	if (data.readInt() == reply.readInt()) //Check if the service returns us this number
	{
		final String _openUDID = reply.readString();
		if (_openUDID != null) { //if valid OpenUDID, save it
			if (LOG) Log.d(TAG, "Received " + _openUDID);

			if (mReceivedOpenUDIDs.containsKey(_openUDID)) mReceivedOpenUDIDs.put(_openUDID, mReceivedOpenUDIDs.get(_openUDID) + 1);
			else mReceivedOpenUDIDs.put(_openUDID, 1);
				
		}
	}
} catch (RemoteException e) {if (LOG) Log.e(TAG, "RemoteException: " + e.getMessage());}		    	    			
mContext.unbindService(this);

startService(); //Try the next one
	}
 
Example 2
Project: boohee_v5.6   File: DeviceHelper.java   Source Code and License Vote up 6 votes
public String getAdvertisingID() {
    try {
        Intent intent = new Intent("com.google.android.gms.ads.identifier.service.START");
        intent.setPackage("com.google.android.gms");
        Object gSConnection = new GSConnection();
        this.context.bindService(intent, gSConnection, 1);
        IBinder takeBinder = gSConnection.takeBinder();
        Parcel obtain = Parcel.obtain();
        Parcel obtain2 = Parcel.obtain();
        obtain.writeInterfaceToken("com.google.android.gms.ads.identifier.internal" +
                ".IAdvertisingIdService");
        takeBinder.transact(1, obtain, obtain2, 0);
        obtain2.readException();
        String readString = obtain2.readString();
        obtain2.recycle();
        obtain.recycle();
        Ln.i("getAdvertisingID === %s", readString);
        return readString;
    } catch (Throwable th) {
        Ln.w(th);
        return null;
    }
}
 
Example 3
Project: DroidIPC   File: ServiceManagerThread.java   Source Code and License Vote up 3 votes
private void activeClientGetService() {
	
	if(isReady()){
		for (Iterator<Map.Entry<String,IBinder>> iter = mClientServiceManagerContainer.entrySet().iterator();iter.hasNext();) {
			
			Map.Entry<String,IBinder> me = iter.next();
			
			IBinder clientServiceManager = me.getValue();
			
			Parcel reply = Parcel.obtain();
			
			try {
				clientServiceManager.transact(ServiceContext.ACTIVE_CLIEINT_SERVCIE_GETSERVICE, Parcel.obtain(), reply, 0);
				
				int result = reply.readInt();
				
				if(result == ServiceContext.SUCCESS) {
					
					LogControler.print(Level.INFO, "[ServerManagerThread] activeClientGetService success");
					
				} else {
					
					LogControler.print(Level.INFO, "[ServerManagerThread] activeClientGetService fail");
					
				}
				
			} catch (RemoteException e) {
				e.printStackTrace();
			}
			
		}
	}
	
}