0

I am considering the code in this question, and did the following:

First, I create a simple, empty project with only one Activity called MainActivity, which is in package com.example.plugins. I compile this project and install it to my device. The app works fine.

Then, in another project I have this code:

Intent plugins = new Intent();
plugins.setClassName("com.example.plugins", "MainActivity");
List<ResolveInfo> list = getPackageManager().queryIntentActivities(plugins,
                PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0) {
    tvText.setText("Plugins.");
} else {
    tvText.setText("No Plugins.");
}

I'd say this should work, but it doesn't. It gives "no plugins". Am I missing something here?

Update When using

PackageInfo pi = getPackageManager().getPackageInfo(
                    "com.example.plugins", PackageManager.GET_ACTIVITIES);

I do get the activities from that other app.

Community
  • 1
  • 1
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195

2 Answers2

0

I think the MIME-type of the Intent is missing.

plugins.setType("text/plain");
qantik
  • 1,067
  • 1
  • 10
  • 20
0

When setting the class name, you have to use the complete name, including package:

plugins.setClassName("com.example.plugins", "com.example.plugins.MainActivity");
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195