4

I'm developing an application that needs to be called by another application. Both applications will be installed in my Android device. I need application A to search for application B and the call it.

I have the following requirement from my company:

an intent must also have its type attribute set to application/mycompanyname.com and it will be discovered using PackageManager.queryIntentActivities(Intent intent, int flags) with the intent described to see if any activity is available.

But I'm having trouble to register it. Since now I've tried this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testpublishintent"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".ReceiverDemo">
        <intent-filter>
            <action android:name="marakana.intent.action.ReceiverDemo" />
          </intent-filter>
    </receiver>
</application>

</manifest>

And I'm looking for all installed apps like this:

void GetInstalledAppList()
{
  final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
  mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  final List pkgAppsList = getPackageManager().queryIntentActivities( mainIntent, 0);
  for (Object object : pkgAppsList) 
  {
    ResolveInfo info = (ResolveInfo) object;
    Drawable icon    = getBaseContext().getPackageManager().getApplicationIcon(info.activityInfo.applicationInfo);
    String strAppName   = info.activityInfo.applicationInfo.publicSourceDir.toString();
    String strPackageName  = info.activityInfo.applicationInfo.packageName.toString();
    final String title  = (String)((info != null) ? getBaseContext().getPackageManager().getApplicationLabel(info.activityInfo.applicationInfo) : "???");
   }
 }

But I don't know if this is correct as I can see the installed app but not instantiate it. Can anybody correct me please?

Sonhja
  • 8,230
  • 20
  • 73
  • 131

1 Answers1

0

I think you can have a look to this page of the documentation, they're basically explaining all what you need.

It works this way: you register the activity you want to start by defining some IntentFilter in its Manifest and then you start this intent from the original Activity.

But, if you want a custom intent, I'd have a look to do this StackOverflow Thread (you didn't say which kind of intent you wanted)

Community
  • 1
  • 1
Laurent Meyer
  • 2,766
  • 3
  • 33
  • 57