Alan Wang
Alan Wang

Reputation: 31

how to set ComponentName?

I want to sendBroadcast to other app, the app package is com.android.cci the class is in folder engtest and name as FtmEngButtons, so which ComponentName setting should be correct

  1. ComponentName("com.android.cci", "com.android.cci.engtest.FtmEngButtons");
  2. ComponentName("com.android.cci.engtest", "FtmEngButtons");
  3. ComponentName("com.android.cci", "com.android.cci.FtmEngButtons");
  4. ComponentName("com.android.cci.engtest", "com.android.cci.engtest.FtmEngButtons");
  5. or others?

Upvotes: 1

Views: 2721

Answers (1)

Ameya Pandilwar
Ameya Pandilwar

Reputation: 2778

If you take a look at the documentation provided for ComponentName, it states that "Two pieces of information, encapsulated here, are required to identify a component: the package (a String) it exists in, and the class (a String) name inside of that package."

So, in this ComponentName constructor, the first argument is not the package name of the class but rather the package name of the application.

Based on this, the first option is the correct one -- ComponentName("com.android.cci", "com.android.cci.engtest.FtmEngButtons");

For Reference -- https://developer.android.com/reference/android/content/ComponentName.html

Upvotes: 1

Related Questions