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

时间:2015-01-19 23:51:39

标签: android android-intent

我有一个App1应该启动一组应用App2,App3 ......,

我知道我可以指定包名称,但我更喜欢发送BroadCast来启动我开发的一组应用程序,所有这些都是同时进行的,而不必担心检查它们中的哪一个已安装。

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

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个应用:[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永远不会开始:/,任何想法?

我最诚挚的问候

1 个答案:

答案 0 :(得分:0)

尝试

context.startActivity(dispara);

而不是

context.sendBroadcast(dispara);