Android ShareActionProvider图像问题

时间:2013-08-04 00:10:11

标签: android image shareactionprovider

我正在尝试从我正在开发的应用程序发送图像,我有以下代码,但是如果从我/可绘制文件夹中的文件创建一个Uri,任何想法都被卡住了? (此时非常困惑)

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.second, menu);
    MenuItem shareitem = menu.findItem(R.id.menu_item_share);
    myShareActionProvider = (ShareActionProvider) shareitem.getActionProvider();
    myShareActionProvider.setShareIntent(createShareIntent());

    ActionBar actionBar = getActionBar();
    actionBar.show();
    return true;

}

public Intent createShareIntent() {
    image = ???
    Uri uri = Uri.fromFile(image);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.setType("image/png");
    return shareIntent;
}

2 个答案:

答案 0 :(得分:1)

private Intent createShareIntent() {
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("image/*");
        Uri uri = Uri.parse("android.resource://your.package.name/" + R.drawable.image);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        return shareIntent;
    }

答案 1 :(得分:0)

进一步提出我的问题,如果我有以下内容(数字是一个变量,根据按下的按钮而变化)。为什么以下不起作用?

public Intent createShareIntent() {
    Intent intent = getIntent();
    int number = intent.getIntExtra("BUTTON NUMBER", 1);
    Uri imageUri = Uri.parse("android.resource://" + getPackageName() + "/"+ R.raw."BUTTON NUMBER");
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    shareIntent.setType("image/*");
    return shareIntent;

}
相关问题