0

Mixare has an application (Open source) that lets you view POIs with your camera. It gives you the possibility to call the app from your application thanks to this :

Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("http://ws.geonames.org/findNearbyWikipediaJSON"), "application/mixare-json");
startActivity(i);

The problem is that user must have the app installed in addition to my app, so what I did is that I imported the whole app within mine, with all its resources and stuff.
But I don't know how to call the main activity MainActivity.java, which resides in the package org.mixare.
How can I make an intent to call this activity ? And how do I declare it in the manifest ?

Mehdiway
  • 10,337
  • 8
  • 36
  • 68

4 Answers4

2

If you have added the code and resources of the app to your own app, then you should declare and call it's activities as they were your own.

Intent i = new Intent(this, MainActivity.class);
startActivity(i);

This being said, it's not a trivial task. You need to merge AndroidManifest and could get into trouble if you don't know what you're doing. For instance, user can have the Mixare app in addition to yours and intent could have same actions etc.

There is an alternative to this. You could check if Mixare app is installed and if not ask user to do so. This could be more "android way of doing things", depending on your use case.

matiash
  • 54,791
  • 16
  • 125
  • 154
Nemanja Kovacevic
  • 3,510
  • 2
  • 30
  • 45
1

Look at, http://code.google.com/p/mixare/wiki/DisplayYourOwnData for how to start mixare via Intent.

Alternatively, you can use mixare as your library project and then call its MainActivity class directly from your application as Using an Android library project Activity within another project.

Quoting the same here -

Declaring library components in the manifest file

In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any , , , , and so on, as well as , , and similar elements.

Declarations should reference the library components by their fully-qualified package names, where appropriate.

Then you can definitely call,

Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
Community
  • 1
  • 1
sjain
  • 23,126
  • 28
  • 107
  • 185
1

No, it is very hard to do a 2+2=4 kind of addition of manifest files etc.

I see there are two ways to handle this:

  1. Use the external app: Check if the user has external app you want him to have. Else, direct him to the right link. You can get the package name of the publiched app and use it in this function:

    private boolean appInstalledOrNot(String uri) { PackageManager pm = getPackageManager(); boolean app_installed = false; try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); app_installed = true; } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed ; }

  2. Combining code: This has no direct/correct answer. You need to study the code and integrate with your existing one.

spiralarchitect
  • 880
  • 7
  • 19
0
//appPackageName,appClassName can be found in Logcat
ComponentName component = new ComponentName("appPackageName","appClassName");
Intent intent = new Intent();
intent.setComponent(component);
startActivity(intent);
wffger
  • 86
  • 1
  • 9