共用方式為


Activity.CallingPackage Property

Definition

Return the name of the package that invoked this activity.

public virtual string? CallingPackage { [Android.Runtime.Register("getCallingPackage", "()Ljava/lang/String;", "GetGetCallingPackageHandler")] get; }
[<get: Android.Runtime.Register("getCallingPackage", "()Ljava/lang/String;", "GetGetCallingPackageHandler")>]
member this.CallingPackage : string

Property Value

The package of the activity that will receive your reply, or null if none.

Attributes

Remarks

Return the name of the package that invoked this activity. This is who the data in #setResult setResult() will be sent to. You can use this information to validate that the recipient is allowed to receive the data.

<p class="note">Note: if the calling activity is not expecting a result (that is it did not use the #startActivityForResult form that includes a request code), then the calling package will be null.</p>

<p class="note">Note: prior to android.os.Build.VERSION_CODES#JELLY_BEAN_MR2, the result from this method was unstable. If the process hosting the calling package was no longer running, it would return null instead of the proper package name. You can use #getCallingActivity() and retrieve the package name from that instead.</p>

Java documentation for android.app.Activity.getCallingPackage().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to