Android选择您的应用程序可以将图像附加到SMS / MMS消息

时间:2015-01-23 15:32:11

标签: android image attachment

我很难找到信息,以便实现:

  1. 用户正在发短信

  2. 点击附件以添加图片

  3. 您的应用还会显示其他可能性

  4. 我应该在主要活动或清单中添加任何内容吗?

    编辑:解答如下。

    如何将所选图像从应用程序返回到短信/短信?

    我的代码再次启动共享操作,因此您需要再次输入接收器,这不是最佳选择:

     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();
            }
    
    
        }
    
    
    
        } );
    

1 个答案:

答案 0 :(得分:0)

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

    <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>