This is my code given below.FrameLayout is Used to share as JPEG Image on twitter.This is the code Im trying .
sharesp=(Spinner)findViewById(R.id.spnrShare);
sharesp.setAdapter(new MyShAdapter(MainActivity.this, R.layout.rowview, Sharestring));
sharesp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v,
int position, long arg3) {
// TODO Auto-generated method stub
selectitem=parent.getItemAtPosition(position).toString();
selecetint=position;
if(selectitem=="FaceBook" || selecetint==R.drawable.fbbtn){
shareFbook();
}
else if(selectitem=="Twitter" || selecetint==R.drawable.twitbtn){
shareTwitter();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
public void shareTwitter(){
FrameLayout savFrame_layout=(FrameLayout)findViewById(R.id.frame);
try {
if(MainActivity.this.mainFrame_layout==null){
MainActivity.this.mainFrame_layout.setDrawingCacheEnabled(true);
MainActivity.this.mainFrame_layout.refreshDrawableState();
MainActivity.this.mainFrame_layout.buildDrawingCache();
MainActivity.this.bm_ImgFrame = mainFrame_layout.getDrawingCache();
int i1=100000;
Random random=new Random();
i1=random.nextInt(i1);
MainActivity.fname = "Quick_"+ i1 + ".jpg";
String pathy=Environment.getExternalStorageDirectory()+File.separator+"/MYAnApps";
MainActivity.this.rootFile=new File(pathy);
MainActivity.this.sdImageMainDirectory = new File(MainActivity.this.rootFile + MainActivity.fname);
FileOutputStream fileOutputStream = new FileOutputStream(MainActivity.this.sdImageMainDirectory);
bm_ImgFrame.compress(CompressFormat.JPEG, 80, fileOutputStream);
Uri uri = Uri.parse(MainActivity.this.sdImageMainDirectory.getAbsolutePath());
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("/*");
intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity");
intent.putExtra(Intent.EXTRA_TEXT, "MyAndroidApp: https://play.google.com/store/apps/details?id=com.example.MyApp");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(MainActivity.this.sdImageMainDirectory));
startActivity(intent);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Try using
"*/*"
as MIME, so you can send any generic data type.Also try changing
ACTION_SEND
toACTION_SEND_MULTIPLE
which specialized for delivering multiple data.More info about ACTION_SEND_MULTPLE and handling MIME types.