Most visited

Recently visited

Added in API level 4

IntentSender

public class IntentSender
extends Object implements Parcelable

java.lang.Object
   ↳ android.content.IntentSender


描述要执行的Intent和目标操作。 返回的对象可以交给其他应用程序,以便他们可以执行您稍后代表您所描述的操作。

通过给另一个应用程序提供一个IntentSender,您可以授予它执行您指定的操作的权限,就好像另一个应用程序是您自己的一样(具有相同的权限和标识)。 因此,您应该小心如何构建IntentSender:例如,通常,您提供的基本Intent会将组件名称明确设置为您自己的组件之一,以确保它最终发送到那里和其他地方。

IntentSender本身只是对由系统维护的令牌的引用,描述了用于检索原始数据的原始数据。 这意味着,即使其拥有的应用程序的进程被终止,IntentSender本身仍然可以从其他被赋予的进程中使用。 如果稍后创建的应用程序重新获取相同类型的IntentSender(相同的操作,相同的Intent操作,数据,类别和组件以及相同的标志),它将收到一个表示相同标记的IntentSender(如果该标记仍然有效)。

这个类的实例不能直接创建,而必须从现有的 PendingIntentPendingIntent.getIntentSender()

Summary

Nested classes

interface IntentSender.OnFinished

回调界面用于发现发送操作何时完成。

class IntentSender.SendIntentException

尝试通过已取消的PendingIntent发送异常或者不能再执行请求时抛出异常。

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<IntentSender> CREATOR

Public methods

int describeContents()

描述此Parcelable实例的封送表示中包含的特殊对象的种类。

boolean equals(Object otherObj)

两个IntentSender对象的比较运算符,例如返回true,然后它们表示来自同一个包的相同操作。

String getCreatorPackage()

返回创建此IntentSender的应用程序的包名称,即您将实际发送该Intent的身份。

int getCreatorUid()

返回创建此PendingIntent的应用程序的uid,即您将实际发送Intent的身份。

UserHandle getCreatorUserHandle()

返回创建此PendingIntent的应用程序的用户句柄,即您实际上将发送Intent的用户。

String getTargetPackage()

此方法在API级别17中已被弃用。重命名为getCreatorPackage()

int hashCode()

返回对象的哈希码值。

static IntentSender readIntentSenderOrNullFromParcel(Parcel in)

便捷功能,用于从Parcel中读取Messenger或空指针。

void sendIntent(Context context, int code, Intent intent, IntentSender.OnFinished onFinished, Handler handler)

执行与此IntentSender相关的操作,允许调用者指定关于要使用的Intent的信息,并在发送完成时收到通知。

void sendIntent(Context context, int code, Intent intent, IntentSender.OnFinished onFinished, Handler handler, String requiredPermission)

执行与此IntentSender相关的操作,允许调用者指定关于要使用的Intent的信息,并在发送完成时收到通知。

String toString()

返回对象的字符串表示形式。

static void writeIntentSenderOrNullToParcel(IntentSender sender, Parcel out)

用于写入IntentSender或空指针到Parcel的便捷函数。

void writeToParcel(Parcel out, int flags)

将此对象平铺到一个包裹中。

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Fields

CREATOR

Added in API level 4
Creator<IntentSender> CREATOR

Public methods

describeContents

Added in API level 4
int describeContents ()

描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象将在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

equals

Added in API level 4
boolean equals (Object otherObj)

两个IntentSender对象的比较运算符,例如返回true,然后它们表示来自同一个包的相同操作。

Parameters
otherObj Object: the reference object with which to compare.
Returns
boolean true if this object is the same as the obj argument; false otherwise.

getCreatorPackage

Added in API level 17
String getCreatorPackage ()

返回创建此IntentSender的应用程序的包名称,即您将实际发送该Intent的身份。 返回的字符串由系统提供,因此应用程序无法欺骗其包。

Returns
String The package name of the PendingIntent, or null if there is none associated with it.

getCreatorUid

Added in API level 17
int getCreatorUid ()

返回创建此PendingIntent的应用程序的uid,即您将实际发送Intent的身份。 返回的整数由系统提供,以便应用程序不能欺骗其uid。

Returns
int The uid of the PendingIntent, or -1 if there is none associated with it.

getCreatorUserHandle

Added in API level 17
UserHandle getCreatorUserHandle ()

返回创建此PendingIntent的应用程序的用户句柄,即您实际上将发送Intent的用户。 返回的UserHandle由系统提供,以便应用程序不能欺骗其用户。 有关用户句柄的更多说明,请参阅Process.myUserHandle()

Returns
UserHandle The user handle of the PendingIntent, or null if there is none associated with it.

getTargetPackage

Added in API level 9
String getTargetPackage ()

此方法在API级别17中已弃用。
重命名为getCreatorPackage()

Returns
String

hashCode

Added in API level 4
int hashCode ()

返回对象的哈希码值。 为了散列表的好处而支持此方法,例如由HashMap提供的HashMap

hashCode的总合同是:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

尽可能合理实用,由类Object定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但Java TM编程语言不需要此实现技术。)

Returns
int a hash code value for this object.

readIntentSenderOrNullFromParcel

Added in API level 4
IntentSender readIntentSenderOrNullFromParcel (Parcel in)

便捷功能,用于从Parcel中读取Messenger或空指针。 您必须先写好信使writeIntentSenderOrNullToParcel(IntentSender, Parcel)

Parameters
in Parcel: The Parcel containing the written Messenger.
Returns
IntentSender Returns the Messenger read from the Parcel, or null if null had been written.

sendIntent

Added in API level 4
void sendIntent (Context context, 
                int code, 
                Intent intent, 
                IntentSender.OnFinished onFinished, 
                Handler handler)

执行与此IntentSender相关的操作,允许调用者指定关于要使用的Intent的信息,并在发送完成时收到通知。

Parameters
context Context: The Context of the caller. This may be null if intent is also null.
code int: Result code to supply back to the IntentSender's target.
intent Intent: Additional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent. Use null to not modify the original Intent.
onFinished IntentSender.OnFinished: The object to call back on when the send has completed, or null for no callback.
handler Handler: Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
Throws
IntentSender.SendIntentException Throws CanceledIntentException if the IntentSender is no longer allowing more intents to be sent through it.

sendIntent

Added in API level 14
void sendIntent (Context context, 
                int code, 
                Intent intent, 
                IntentSender.OnFinished onFinished, 
                Handler handler, 
                String requiredPermission)

执行与此IntentSender相关的操作,允许调用者指定关于要使用的Intent的信息,并在发送完成时收到通知。

Parameters
context Context: The Context of the caller. This may be null if intent is also null.
code int: Result code to supply back to the IntentSender's target.
intent Intent: Additional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent. Use null to not modify the original Intent.
onFinished IntentSender.OnFinished: The object to call back on when the send has completed, or null for no callback.
handler Handler: Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
requiredPermission String: Name of permission that a recipient of the PendingIntent is required to hold. This is only valid for broadcast intents, and corresponds to the permission argument in Context.sendOrderedBroadcast(Intent, String). If null, no permission is required.
Throws
IntentSender.SendIntentException Throws CanceledIntentException if the IntentSender is no longer allowing more intents to be sent through it.

toString

Added in API level 4
String toString ()

返回对象的字符串表示形式。 一般来说, toString方法返回一个“文本表示”该对象的字符串。 结果应该是一个简洁但内容丰富的表述,对于一个人来说很容易阅读。 建议所有子类重写此方法。

toString类的方法Object返回一个字符串,其中包含对象为实例的类的名称,符号字符“ @ ”以及对象的哈希代码的无符号十六进制表示形式。 换句话说,这个方法返回一个字符串,其值等于:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

writeIntentSenderOrNullToParcel

Added in API level 4
void writeIntentSenderOrNullToParcel (IntentSender sender, 
                Parcel out)

用于写入IntentSender或空指针到Parcel的便捷函数。 您必须将其与readIntentSenderOrNullFromParcel(Parcel)一起使用, readIntentSenderOrNullFromParcel(Parcel)供以后阅读。

Parameters
sender IntentSender: The IntentSender to write, or null.
out Parcel: Where to write the IntentSender.

writeToParcel

Added in API level 4
void writeToParcel (Parcel out, 
                int flags)

将此对象平铺到一个包裹中。

Parameters
out Parcel: The Parcel in which the object should be written.
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.

Hooray!