Android 在将图像附加到 SMS/MMS 消息的可能性中选择您的应用

Android choose your app among possibilities to attach image to SMS/MMS message

我很难找到要实现的信息:

  1. 用户正在发短信

  2. 点击附件添加图片

  3. 您的应用程序也显示在其他可能性中

我应该向 Main activity 或清单中添加任何内容吗?

编辑:下面答案中的解决方案。

如何return从应用返回sms/mms选择的图像?

我的代码再次开始分享操作,因此您需要再次输入接收者,这不是最优的:

 public class StartActivity extends Activity {

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



Intent myIntent = getIntent();
final int image = myIntent.getExtras().getInt("image");

ImageView imagefull = (ImageView)findViewById(R.id.imageView1);
imagefull.setImageResource(image);




Button share = (Button) findViewById (R.id.buttonshare);
share.setOnClickListener(new OnClickListener() 

{
    @Override
    public void onClick(View arg0) {

        Bitmap bitmap;
        OutputStream output;    

        bitmap = BitmapFactory.decodeResource(getResources(),
        image);

        File filepath = Environment.getExternalStorageDirectory();

        File dir = new File(filepath.getAbsolutePath() + "/Shared Movie Quotes/");
        dir.mkdirs();

        File file = new File(dir, "quote.png");

        try {

            // Share Intent
            Intent share = new Intent(Intent.ACTION_SEND);

            // Type of file to share
            share.setType("image/jpeg");

            output = new FileOutputStream(file);

            // Compress into png format image from 0% - 100%
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
            output.flush();
            output.close();

            // Locate the image to Share
            Uri uri = Uri.fromFile(file);

            // Pass the image into an Intnet
            share.putExtra(Intent.EXTRA_STREAM, uri);

            // Show the social share chooser list
            startActivity(Intent.createChooser(share, "Let them know!"));

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }



    } );

尝试添加以下意图过滤器:

    <activity android:name="YourActivity">
        <!-- filter for showing when image is selected -->
        <intent-filter>
    <action android:name="android.intent.action.GET_CONTENT" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>

    </activity>