我很难找到信息,该怎么做才能实现:
-
用户正在发送短信
-
单击附件以添加图像
-
您的应用程序还会显示其他可能性
我应该向我的主活动或清单添加任何内容吗?
编辑:解决方案在下面的答案中。
如何将所选图像从应用程序返回到短信/彩信?
我的代码再次开始共享操作,因此您需要再次输入接收器,这不是最佳的:
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>