这是我在下面给出的代码。FrameLayout 用于在 twitter 上共享为 JPEG 图像。这是我正在尝试的代码。
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();
}
}