Java Code Examples for android.content.Intent.writeToParcel()

The following are Jave code examples for showing how to use writeToParcel() of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: letv   File: RemoteDeviceManager.java   View Source Code Vote up 7 votes
public void startActivity(String deviceId, Intent intent) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(deviceId);
        if (intent != null) {
            _data.writeInt(1);
            intent.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        this.mRemote.transact(11, _data, _reply, 0);
        ExceptionUtils.readExceptionFromParcel(_reply);
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 2
Project: letv   File: RemoteDeviceManager.java   View Source Code Vote up 7 votes
public void sendBroadcast(String deviceId, Intent intent) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(deviceId);
        if (intent != null) {
            _data.writeInt(1);
            intent.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        this.mRemote.transact(12, _data, _reply, 0);
        ExceptionUtils.readExceptionFromParcel(_reply);
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 3
Project: letv   File: DeviceCallback.java   View Source Code Vote up 7 votes
public void onPackageChange(String deviceId, Intent intent) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        _data.writeString(deviceId);
        if (intent != null) {
            _data.writeInt(1);
            intent.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        this.mRemote.transact(5, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }
}
 
Example 4
Project: FreshMember   File: DaemonStrategy23.java   View Source Code Vote up 6 votes
@SuppressLint("Recycle")// when process dead, we should save time to restart and kill self, don`t take a waste of time to recycle
	private void initBroadcastParcel(Context context, String broadcastName){
		Intent intent = new Intent();
        ComponentName componentName = new ComponentName(context.getPackageName(), broadcastName);
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
		
		/*	 
//      Object contextImpl = ((Application)context.getApplicationContext()).getBaseContext();
        //this context is ContextImpl, get MainThread instance immediately
        Field mainThreadField = context.getClass().getDeclaredField("mMainThread");
        mainThreadField.setAccessible(true);
      	Object mainThread = mainThreadField.get(context);
      	//get ApplicationThread instance
      	Object applicationThread = mainThread.getClass().getMethod("getApplicationThread").invoke(mainThread);  
      	//get Binder
      	Binder callerBinder = (Binder) (applicationThread.getClass().getMethod("asBinder").invoke(applicationThread));
		 */
      
//      	UserHandle userHandle = android.os.Process.myUserHandle();
//      	int handle = (Integer) userHandle.getClass().getMethod("getIdentifier").invoke(userHandle);
		
      	mBroadcastData = Parcel.obtain();
      	mBroadcastData.writeInterfaceToken("android.app.IActivityManager");
//      	mBroadcastData.writeStrongBinder(callerBinder);
      	mBroadcastData.writeStrongBinder(null);
      	intent.writeToParcel(mBroadcastData, 0);
      	mBroadcastData.writeString(intent.resolveTypeIfNeeded(context.getContentResolver()));
      	mBroadcastData.writeStrongBinder(null);
      	mBroadcastData.writeInt(Activity.RESULT_OK);
      	mBroadcastData.writeString(null);
      	mBroadcastData.writeBundle(null);
      	mBroadcastData.writeString(null);
      	mBroadcastData.writeInt(-1);
      	mBroadcastData.writeInt(0);
      	mBroadcastData.writeInt(0);
//      	mBroadcastData.writeInt(handle);
      	mBroadcastData.writeInt(0);
	}
 
Example 5
Project: FreshMember   File: DaemonStrategyXiaomi.java   View Source Code Vote up 6 votes
@SuppressLint("Recycle")// when process dead, we should save time to restart and kill self, don`t take a waste of time to recycle
	private void initServiceParcel(Context context, String serviceName){
		Intent intent = new Intent();
		ComponentName component = new ComponentName(context.getPackageName(), serviceName);
		intent.setComponent(component);
		
		/*  
        //get ContextImpl instance
//          Object contextImpl = ((Application)context.getApplicationContext()).getBaseContext();
          //this context is ContextImpl, get MainThread instance immediately
          Field mainThreadField = context.getClass().getDeclaredField("mMainThread");
          mainThreadField.setAccessible(true);
          Object mainThread = mainThreadField.get(context);
          //get ApplicationThread instance
          Object applicationThread = mainThread.getClass().getMethod("getApplicationThread").invoke(mainThread);  
          //get Binder
          Binder callerBinder = (Binder) (applicationThread.getClass().getMethod("asBinder").invoke(applicationThread));  
          */
          
          //get handle
//          UserHandle userHandle = android.os.Process.myUserHandle();
//          int handle = (Integer) userHandle.getClass().getMethod("getIdentifier").invoke(userHandle);
          
          //write pacel
          mServiceData = Parcel.obtain();
          mServiceData.writeInterfaceToken("android.app.IActivityManager");
          mServiceData.writeStrongBinder(null);
//          mServiceData.writeStrongBinder(callerBinder);
          intent.writeToParcel(mServiceData, 0);
          mServiceData.writeString(null);
//          mServiceData.writeString(intent.resolveTypeIfNeeded(context.getContentResolver()));
          mServiceData.writeInt(0);
//          mServiceData.writeInt(handle);
		
	}
 
Example 6
Project: FreshMember   File: DaemonStrategy22.java   View Source Code Vote up 6 votes
@SuppressLint("Recycle")// when process dead, we should save time to restart and kill self, don`t take a waste of time to recycle
	private void initServiceParcel(Context context, String serviceName){
		Intent intent = new Intent();
		ComponentName component = new ComponentName(context.getPackageName(), serviceName);
		intent.setComponent(component);
		
		/*  
        //get ContextImpl instance
//          Object contextImpl = ((Application)context.getApplicationContext()).getBaseContext();
          //this context is ContextImpl, get MainThread instance immediately
          Field mainThreadField = context.getClass().getDeclaredField("mMainThread");
          mainThreadField.setAccessible(true);
          Object mainThread = mainThreadField.get(context);
          //get ApplicationThread instance
          Object applicationThread = mainThread.getClass().getMethod("getApplicationThread").invoke(mainThread);  
          //get Binder
          Binder callerBinder = (Binder) (applicationThread.getClass().getMethod("asBinder").invoke(applicationThread));  
          */
          
          //get handle
//          UserHandle userHandle = android.os.Process.myUserHandle();
//          int handle = (Integer) userHandle.getClass().getMethod("getIdentifier").invoke(userHandle);
          
          //write pacel
          mServiceData = Parcel.obtain();
          mServiceData.writeInterfaceToken("android.app.IActivityManager");
          mServiceData.writeStrongBinder(null);
//          mServiceData.writeStrongBinder(callerBinder);
          intent.writeToParcel(mServiceData, 0);
          mServiceData.writeString(null);
//          mServiceData.writeString(intent.resolveTypeIfNeeded(context.getContentResolver()));
          mServiceData.writeInt(0);
//          mServiceData.writeInt(handle);
		
	}
 
Example 7
Project: chromium-for-android-56-debug-video   File: IntentUtils.java   View Source Code Vote up 3 votes
/**
 * Returns how large the Intent will be in Parcel form, which is helpful for gauging whether
 * Android will deliver the Intent instead of throwing a TransactionTooLargeException.
 *
 * @param intent Intent to get the size of.
 * @return Number of bytes required to parcel the Intent.
 */
public static int getParceledIntentSize(Intent intent) {
    Parcel parcel = Parcel.obtain();
    intent.writeToParcel(parcel, 0);
    return parcel.dataSize();
}