0

I tried to start the Wikipedia App via Intent but I always get an InvocationTargetException, because the Activity can't be found. I can detect that Wikipedia is installed, but I can't start it. I know that I can also use the Intent Filter and call the Wikipedia URL, but then the user can decide between app and browser (both works different with the search param, which is not very useful) and I want to decide it for the user.

I tried it with following code:

final Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "searchString");
intent.setType("text/plain");
intent.setPackage("org.wikipedia");

Can somebody tell me, what I am doing wrong there or is it just not possible to start the wikipedia app? :-/

Strassenrenner
  • 179
  • 1
  • 11
  • see http://stackoverflow.com/questions/2780102/open-another-application-from-your-own-intent, but this sentence is not good **I want to decide it for the user** – Shayan Pourvatan Dec 28 '14 at 12:51
  • thx, but it only means that I dont want that the user clicks too much - it is just a usability decision – Strassenrenner Jan 20 '15 at 12:54

1 Answers1

1

Finally I come to a solution after I was looking in the wikipedia code on github (https://github.com/wikimedia/apps-android-wikipedia). The app listens only for View Intents, which means that following code works:

final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(searchUri);
intent.setPackage("org.wikipedia");

The problem here is, that only URI's for existing articles were handled and no search operation can be used. After watching a little bit more in the code, I found a PageActivity which also listens for ACTION_SEARCH Intents. This would work, when in the AndroidManifest.xml this Intent Filter would be also available.

Strassenrenner
  • 179
  • 1
  • 11