paddy
paddy

Reputation: 47

How to get the package name of an external app which calls my app

My app com.test.sample is invoked by an external app com.testExternal.outsideApp. The external app uses an intent to invoke the MainActivity of com.test.sample by calling the startActivityForResult. What I am looking for is a way to programmatically obtain the package name of the external app. I tried several ways like

String parentPackageName = this.getParent().getPackageName();
//This fails since the parent is always returning NULL.

String packageName = this.getIntent().getPackage();
//This returns the package name of the current application which is not what I want.

Is there any other way to get the package name of the caller app?

Upvotes: 2

Views: 2506

Answers (1)

droidpl
droidpl

Reputation: 5892

You can do it if your application was started with Activity#startActivityForResult by using Activity#getCallingActivity().

Upvotes: 3

Related Questions