queryIntentActivities 找到了接收者,但没有启动

queryIntentActivities found receivers but it doesn't Starts

我有一个 App1,它应该启动一组应用程序 App2、App3...,

我知道我可以指定包名称,但我更喜欢发送 BroadCast 来同时启动我开发的一组应用程序,而不必担心检查安装了哪些应用程序。

应用程序 1 发送检查是否有任何应用程序处理意图,如果有,我发送意图。

Intent dispara = new Intent();
      dispara.setAction("com.ciu.SMV.dispara");
      dispara.putExtra("TimeStamp", timee);
      dispara.setType("text/plain");

      if(verificaReceptor(context,dispara))
          context.sendBroadcast(dispara);

App1 找到处理意图的活动,发送意图,但 App2 从未启动。

public static boolean verificaReceptor(Context context, Intent intent) {
    final PackageManager mgr = context.getPackageManager();
    List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (D)
        Log.d(TAG, "Apps disponibles: " + list.size() + " Apps: "+list + intent);
    return list.size() > 0;
}

记录结果:

/com.ciumx.smv D/onTickBroadCast﹕ Apps disponibles: 1 Apps: [ResolveInfo{412ceab8 com.ciumx.notificador.NotificadorAct p=0 o=0 m=0x608000}]Intent { act=com.ciu.SMV.dispara typ=text/plain (has extras) }

App2 中的清单

<activity
        android:name=".NotificadorAct"
        android:label="@string/title_activity_notificador" >
        <intent-filter android:label="@string/app_name" >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="com.ciu.SMV.dispara" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
    </intent-filter>

    </activity>

App2的OnCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_notificador);

    log("onCreate....", "Creado");

    // Get intent, action and MIME type
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            log("LALA","LLEGÓ TEXTO"); // Handle text being sent
        } else if (type.startsWith("image/")) {
            log("LALA","LLEGÓ imágen"); // Handle text being sent // Handle single image being sent
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            log("LALA","Muchas Imágenes"); // Handle text being sent // Handle multiple images being sent
        }
    } else {
        // Handle other intents, such as being started from the home screen
    }

}

所以 App1 可以看到受体,但 App2 永远不会启动:/,知道吗?

谨致问候

尝试

context.startActivity(dispara);

而不是

context.sendBroadcast(dispara);