2013-03-30 19 views
1

我想通过发送短信在两个应用程序之间进行通信。 这是我第一个包含一个按钮的应用程序,它将调用发送操作,以便所有其他具有操作SEND的应用程序出现在此对话框中。没有应用程序来执行此acion - 对话框始终

((Button) findViewById(R.id.button1)) 
     .setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View arg0) { 
       Intent intent = new Intent(); 
       intent.setAction(Intent.ACTION_SEND); 
       intent.putExtra("ComingFrom", "Activity 1"); 
       final int result = 1; 
       startActivityForResult(Intent.createChooser(intent, "Sending File..."),result); 
      } 
     }); 

现在这是我的第二个应用程序,将获得意图。

// Get the intent that started this activity 
Intent intent = getIntent(); 
Uri data = intent.getData(); 

if (intent != null) { 
    // Figure out what to do based on the intent type 
    if (intent.getType().indexOf("image/") != -1) { 
     // Handle intents with image data ... 
    } else if (intent.getType().equals("text/plain")) { 
     // Handle intents with text ... 
    } 
} 

这是我的第二个应用程序清单,其中包含Action SEND。

<intent-filter> 
      <action android:name="android.intent.action.SEND" /> 

      <category android:name="android.intent.category.DEFAULT" /> 

      <data android:mimeType="text/plain" /> 
      <data android:mimeType="image/*" /> 
     </intent-filter> 

但问题是,我没有得到一个对话框,显示了我的其他应用却显示没有应用程序来执行此操作。 我在做什么错?

回答

3

当你启动你的意图时,你还应该在你的包中添加一个mimetype属性。

intent.setType("text/plain"); 

例如。

2

您需要设置发送文本,图像等的类型,因为type是MIME类型。

您需要使用纯文本/或图像,你需要设置简单的文本或纯文本图像/ *

如果附加任何图像文件或没有,那么它也将打开在android系统

默认应用程序
intent.setType("text/plain"); 

intent.setType("image/*"); 
(与图像文件发送使用)
相关问题