我正在开发一个需要被另一个应用程序调用的应用程序。这两个应用程序都将安装在我的Android
设备中。我需要应用程序A来搜索应用程序B并调用它。
我的公司有以下要求:
意图也必须将其type属性设置为
application/mycompanyname.com
,并使用PackageManager.queryIntentActivities(Intent intent, int flags)
发现它,其目的是描述是否有任何活动可用。
但是我无法注册它。从现在起我就试过这个:
<?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>
我正在寻找所有已安装的应用:
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) : "???");
}
}
但我不知道这是否正确,因为我可以看到已安装的应用程序,但没有实例化它。有人可以纠正我吗?
答案 0 :(得分:0)
我认为您可以查看文档的this page,它们基本上可以解释您需要的所有内容。
它以这种方式工作:您通过在IntentFilter
中定义一些Manifest
来注册您要开始的活动,然后从原始Activity
开始此意图。
但是,如果你想要一个自定义意图,我可以看一下StackOverflow Thread(你没有说出你想要的那种意图)