CQM
CQM

Reputation: 44278

get name of activity within Intent

I am using some various ad networks, they all require their own activity names to be added to the manifest.

I want to know when users click them, so I put in an override for startActivity(Intent intent) but I need to inspect the intent object to conditionally set some values.

for instance, with tap for tap's network, it will launch an activity from the class com.ads.TapForTap.. upon a click this will call startActivity(Intent intent) how do I get the name of the class from the intent?

thanks

Upvotes: 5

Views: 25432

Answers (3)

user3294126
user3294126

Reputation: 381

You can use the given intent argument's component class name. Remember the class name might be empty!

intent.getComponent().getClassName()

Upvotes: 28

A--C
A--C

Reputation: 36449

The following line should return the fully qualified name of the Activity you want to start if you have:

  • The Intent that starts an Activity
  • A Context instance (so you can call getPackageManager()).

String className = myIntent.resolveActivity (myContext.getPackageManager()).getClassName();

For more info, see the Intent documentation for resolveActivity().

Upvotes: 4

abhi
abhi

Reputation: 513

try below line to get current activity name,

this.getClass().getSimpleName()

Upvotes: 9

Related Questions