2013-03-30 18 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/*"); 
(與圖像文件發送使用)
相關問題