本文整理匯總了Java中android.os.IBinder.transact方法的典型用法代碼示例。如果您正苦於以下問題:Java IBinder.transact方法的具體用法?Java IBinder.transact怎麽用?Java IBinder.transact使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.IBinder
的用法示例。
在下文中一共展示了IBinder.transact方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onServiceConnected
import android.os.IBinder; //導入方法依賴的package包/類
@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
}
示例2: getAdvertisingID
import android.os.IBinder; //導入方法依賴的package包/類
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;
}
}
示例3: activeClientGetService
import android.os.IBinder; //導入方法依賴的package包/類
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();
}
}
}
}