本文整理汇总了Java中android.os.BadParcelableException类的典型用法代码示例。如果您正苦于以下问题:Java BadParcelableException类的具体用法?Java BadParcelableException怎么用?Java BadParcelableException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BadParcelableException类属于android.os包,在下文中一共展示了BadParcelableException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReferrer
import android.os.BadParcelableException; //导入依赖的package包/类
/**
* Return information about who launched this activity. If the launching Intent
* contains an {@link android.content.Intent#EXTRA_REFERRER Intent.EXTRA_REFERRER},
* that will be returned as-is; otherwise, if known, an
* {@link Intent#URI_ANDROID_APP_SCHEME android-app:} referrer URI containing the
* package name that started the Intent will be returned. This may return null if no
* referrer can be identified -- it is neither explicitly specified, nor is it known which
* application package was involved.
*
* <p>If called while inside the handling of {@link #onNewIntent}, this function will
* return the referrer that submitted that new intent to the activity. Otherwise, it
* always returns the referrer of the original Intent.</p>
*
* <p>Note that this is <em>not</em> a security feature -- you can not trust the
* referrer information, applications can spoof it.</p>
*/
@Nullable
public Uri getReferrer() {
Intent intent = getIntent();
try {
Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
if (referrer != null) {
return referrer;
}
String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME);
if (referrerName != null) {
return Uri.parse(referrerName);
}
} catch (BadParcelableException e) {
Log.w(TAG, "Cannot read referrer from intent;"
+ " intent extras contain unknown custom Parcelable objects");
}
if (mReferrer != null) {
return new Uri.Builder().scheme("android-app").authority(mReferrer).build();
}
return null;
}
示例2: unmarshallParcelable
import android.os.BadParcelableException; //导入依赖的package包/类
/**
* Unmarshalls a parcelable's byte array into the object
*
* @param bytes the byte array
* @param clazz the class
* @param <T> the type
* @return the object
*/
@SuppressWarnings("unchecked")
public static <T extends Parcelable> T unmarshallParcelable(byte[] bytes, Class<T> clazz) {
if (bytes == null) {
return null;
}
Parcel parcel = Parcel.obtain();
parcel.unmarshall(bytes, 0, bytes.length);
parcel.setDataPosition(0);
try {
Parcelable.Creator<? extends Parcelable> creator = (Parcelable.Creator<? extends Parcelable>) clazz.getField("CREATOR").get(null);
return (T) creator.createFromParcel(parcel);
} catch (Exception e) {
throw new BadParcelableException(e);
} finally {
parcel.recycle();
}
}
示例3: unmarshallSerializable
import android.os.BadParcelableException; //导入依赖的package包/类
/**
* Unmarshalls a serializable's byte array into the object
*
* @param bytes the bytes
* @param <T> the type
* @return the object
*/
@SuppressWarnings("unchecked")
public static <T extends Serializable> T unmarshallSerializable(byte[] bytes) {
if (bytes == null) {
return null;
}
Parcel parcel = Parcel.obtain();
parcel.unmarshall(bytes, 0, bytes.length);
parcel.setDataPosition(0);
try {
return (T) parcel.readSerializable();
} catch (Exception e) {
throw new BadParcelableException(e);
} finally {
parcel.recycle();
}
}
示例4: getParcelable
import android.os.BadParcelableException; //导入依赖的package包/类
/**
* Gets a parcelable from an intent
*
* @param intent the intent
* @param name the name
* @param <T> the type
* @return the parcelable
*/
@SuppressWarnings("unchecked")
public static <T extends Parcelable> T getParcelable(Intent intent, String name) {
byte[] bytes = intent.getByteArrayExtra(name);
if (bytes == null) {
return null;
}
try {
ClassLoader intentClassLoader = intent.getExtras().getClassLoader();
String classname = intent.getStringExtra(name + "_CLASSNAME");
Class<T> parcelable;
if (intentClassLoader == null) {
parcelable = (Class<T>) Class.forName(classname);
} else {
parcelable = (Class<T>) Class.forName(classname, true, intentClassLoader);
}
return unmarshallParcelable(bytes, parcelable);
} catch (Exception e) {
throw new BadParcelableException(e);
}
}
示例5: fromBytes_withNullIntent_throwsBadParcelableException
import android.os.BadParcelableException; //导入依赖的package包/类
@Test
public void fromBytes_withNullIntent_throwsBadParcelableException() {
final byte[] intentBytes = toBytesUnchecked(null);
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
@Override
public void call() throws Throwable {
IntentUtil.fromBytes(intentBytes);
}
}).isInstanceOf(BadParcelableException.class);
}
示例6: updateKeySet
import android.os.BadParcelableException; //导入依赖的package包/类
private void updateKeySet() {
// Try to unpack bundle without sandbox
if (!mUseSandbox) {
try {
if (mBundle.keySet() != null) {
mKeys = mBundle.keySet().toArray(mKeys);
mKeysCount = mBundle.size();
} else {
mKeys = new String[0];
mKeysCount = 0;
}
return;
} catch (BadParcelableException ignored) {}
}
// If it failed or was disabled
sandboxBundle(true, null);
}
示例7: onChildAdded
import android.os.BadParcelableException; //导入依赖的package包/类
@SuppressWarnings("unused")
@Subscribe
public void onChildAdded(GameAddedEvent event) {
synchronized (listeners) {
for (ServiceListener listener : listeners) {
try {
listener.gameAdded(event.getGameData());
} catch (RemoteException | BadParcelableException ignore) {
}
}
}
}
示例8: writeToParcel
import android.os.BadParcelableException; //导入依赖的package包/类
public static <D extends Durable> void writeToParcel(Parcel parcel, D d) {
try {
parcel.writeByteArray(writeToArray(d));
} catch (IOException e) {
throw new BadParcelableException(e);
}
}
示例9: readFromParcel
import android.os.BadParcelableException; //导入依赖的package包/类
public static <D extends Durable> D readFromParcel(Parcel parcel, D d) {
try {
return readFromArray(parcel.createByteArray(), d);
} catch (IOException e) {
throw new BadParcelableException(e);
}
}
示例10: sanitizeIntent
import android.os.BadParcelableException; //导入依赖的package包/类
/**
* Sanitizes an intent. In case the intent cannot be unparcelled, all extras will be removed to
* make it safe to use.
* @return A safe to use version of this intent.
*/
public static Intent sanitizeIntent(final Intent incomingIntent) {
if (incomingIntent == null) return null;
try {
incomingIntent.getBooleanExtra("TriggerUnparcel", false);
return incomingIntent;
} catch (BadParcelableException e) {
Log.e(TAG, "Invalid incoming intent.", e);
return incomingIntent.replaceExtras((Bundle) null);
}
}
示例11: asParcelableException
import android.os.BadParcelableException; //导入依赖的package包/类
private RuntimeException asParcelableException(final Throwable e) {
if (e instanceof SecurityException
|| e instanceof BadParcelableException
|| e instanceof IllegalArgumentException
|| e instanceof NullPointerException
|| e instanceof IllegalStateException
|| e instanceof NetworkOnMainThreadException
|| e instanceof UnsupportedOperationException)
return (RuntimeException) e;
return new IllegalStateException(e);
}
示例12: SandboxedObject
import android.os.BadParcelableException; //导入依赖的package包/类
/**
* Constructor for loading from parcel
*/
SandboxedObject(Parcel source) {
try {
mType = Type.values()[source.readInt()];
mHelper = mType.mHelperClass.getDeclaredConstructor(Parcel.class).newInstance(source);
} catch (Exception e) {
throw new BadParcelableException(e);
}
}
示例13: unwrap
import android.os.BadParcelableException; //导入依赖的package包/类
@Override
public Object unwrap(ClassLoader classLoader) {
try {
return Utils.deepCastArray(
(Object[]) super.unwrap(classLoader),
Class.forName(mArrayClassName, true, classLoader)
);
} catch (ClassNotFoundException e) {
throw new BadParcelableException(e);
}
}
示例14: Accessors
import android.os.BadParcelableException; //导入依赖的package包/类
Accessors(String fieldName) throws RemoteException {
mFieldName = fieldName;
// Get value
final SandboxedObject wrappedValue = mSandboxedObject.getFieldValue(mFieldName);
try {
// Try to unwrap, if successful use that value
mCachedValue = wrappedValue.unwrap(null);
} catch (BadParcelableException e) {
// Unwrap failed, use sandbox
mValueIsSandboxed = true;
mCachedStringValue = mSandboxedObject.getFieldValueAsString(mFieldName);
mCachedValue = wrappedValue;
}
}
示例15: intentInvalid
import android.os.BadParcelableException; //导入依赖的package包/类
private static boolean intentInvalid(Intent intent) {
if (intent == null) {
return true;
}
try {
// force unparcelling to check if we are missing classes to
// correctly process callout response
intent.hasExtra(INTENT_RESULT_VALUE);
} catch (BadParcelableException e) {
Log.w(TAG, "unable to unparcel intent: " + e.getMessage());
return true;
}
return false;
}