Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Eclipse:在没有mediaStore.Insert()的情况下将图像共享到facebook_Android_Eclipse_Facebook_Android Intent_Bitmap - Fatal编程技术网

Android Eclipse:在没有mediaStore.Insert()的情况下将图像共享到facebook

Android Eclipse:在没有mediaStore.Insert()的情况下将图像共享到facebook,android,eclipse,facebook,android-intent,bitmap,Android,Eclipse,Facebook,Android Intent,Bitmap,我想分享一个截图到Facebook,Twitter等,使用意图。我找到了一些代码示例,它们通过将图像插入媒体存储,然后获取该图像的URI来实现这一点。但是,我不想用这些无用的图像阻塞用户的设备,我也不想请求访问外部权限,因为我不在应用程序的其他任何地方使用它。有没有一种方法可以构建意图,这样它就可以在不需要URI的情况下共享一个图像?像是直接传递位图,还是在压缩到.png后传递?或者有没有一种方法可以为内存中保存的位图构建URI,而不首先将其设置为文件 我现在用的是: public void s

我想分享一个截图到Facebook,Twitter等,使用意图。我找到了一些代码示例,它们通过将图像插入媒体存储,然后获取该图像的URI来实现这一点。但是,我不想用这些无用的图像阻塞用户的设备,我也不想请求访问外部权限,因为我不在应用程序的其他任何地方使用它。有没有一种方法可以构建意图,这样它就可以在不需要URI的情况下共享一个图像?像是直接传递位图,还是在压缩到.png后传递?或者有没有一种方法可以为内存中保存的位图构建URI,而不首先将其设置为文件

我现在用的是:

public void shareScore(String scoreTextString, String scoreString, Uri screenShotUri){      
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);      
        sharingIntent.setType("image/png");     
        sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, screenShotUri);     
        startActivity(Intent.createChooser(sharingIntent, "Share Via..."));
    }

public Bitmap takeScreenshot(GL10 mGL) {        
    final int mWidth =  this.getGlView().getWidth();
    final int mHeight = this.getGlView().getHeight();
    IntBuffer ib = IntBuffer.allocate(mWidth * mHeight);
    IntBuffer ibt = IntBuffer.allocate(mWidth * mHeight);
    mGL.glReadPixels(0, 0, mWidth, mHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);

    // Convert upside down mirror-reversed image to right-side up normal image.
    for (int i = 0; i < mHeight; i++) {
        for (int j = 0; j < mWidth; j++) {
            ibt.put((mHeight - i - 1) * mWidth + j, ib.get(i * mWidth + j));
        }
    }       

    Bitmap mBitmap = Bitmap.createBitmap(mWidth, mHeight,Bitmap.Config.ARGB_8888);
    mBitmap.copyPixelsFromBuffer(ibt);      
    return mBitmap;
}

private Uri getImageUri(Context inContext, Bitmap inImage) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        inImage.compress(Bitmap.CompressFormat.PNG, 100, bytes);
        String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);     
        return Uri.parse(path);
    }

private void share(){
    String scoreTextString = "I set a new high score on Butterfly Bonanza!";
    String scoreString = "Score :" + Integer.toString(score);               
    Uri screenShotUri = getImageUri(GLGame.class.cast(game), ButterflyBonanza.class.cast(game).getScreenShot());
    ButterflyBonanza.class.cast(game).shareScore(scoreTextString, scoreString, screenShotUri);
}
public void shareScore(String scoreTextString,String scoreString,Uri screenShotUri){
意向共享内容=新意向(android.content.Intent.ACTION\u SEND);
sharingcontent.setType(“image/png”);
sharingIntent.putExtra(android.content.Intent.EXTRA_流,screenShotUri);
startActivity(Intent.createChooser(共享内容,“通过…共享”);
}
公共位图截图(GL10 mGL){
final int mWidth=this.getGlView().getWidth();
final int mHeight=this.getGlView().getHeight();
IntBuffer ib=IntBuffer.allocate(mWidth*mHeight);
IntBuffer ibt=IntBuffer.allocate(mWidth*mHeight);
mGL.glReadPixels(0,0,mWidth,mHight,GL10.GL_RGBA,GL10.GL_无符号字节,ib);
//将倒置的镜像反转图像转换为右侧向上的正常图像。
对于(int i=0;i
URI始终指向文件,因此无法在内存中为位图创建URI

正如您所指出的,您可以将图像直接附加到意图上,如下所示:

 ByteArrayOutputStream bos = new ByteArrayOutputStream();  
 yourBitmap.compress(CompressFormat.PNG, 0, bos);  


 Intent intent = new Intent(); 
 intent.setAction(Intent.ACTION_SEND); 
 intent.setType("*/*"); 
 intent.putExtra(Intent.EXTRA_STREAM, bos.toByteArray());
 startActivity(intent); 

谢谢你,阿努比亚人,我已经编辑了我的问题,并提供了代码片段。我读过,用这种方式发送很慢吗?这是真的吗?我将尝试编辑commentafterintent.setType(“image/png”)^^我改成这样,因为最初我尝试使用此解决方案运行时收到toast询问照片,在使用chooser选择facebook后,它会使facebook应用程序崩溃。此解决方案似乎不适用于与非我自己的活动共享图像。