我真的不知道如何實現Share Intent到我的代碼。有人可以幫助我,我是否需要重寫整個代碼?我爲我的共享意圖使用AsyncTask。我想用共享意圖分享我的圖片。請檢查我的下面的代碼,缺少「方法startActivity(Intent)未定義類型ShareImageTask」。Android共享意圖使用AsyncTask
ShareImageTask.class
public class ShareImageTask extends AsyncTask<String , String , String>
{
private Context context;
private ProgressDialog pDialog;
String image_url;
URL myFileUrl;
String myFileUrl1;
Bitmap bmImg = null;
Intent share;
public ShareImageTask(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(context);
pDialog.setMessage("Downloading Image ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
try {
myFileUrl = new URL(args[0]);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
}
catch (IOException e)
{
e.printStackTrace();
}
try {
String path = myFileUrl.getPath();
String idStr = path.substring(path.lastIndexOf('/') + 1);
File filepath = Environment.getExternalStorageDirectory();
File dir = new File (filepath.getAbsolutePath() + "/Wallpaper/");
dir.mkdirs();
String fileName = idStr;
File file = new File(dir, fileName);
FileOutputStream fos = new FileOutputStream(file);
bmImg.compress(CompressFormat.JPEG, 75, fos);
fos.flush();
fos.close();
share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM,file);
context.startActivity(Intent.createChooser(share, "Share Image"));
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String args) {
// TODO Auto-generated method stub
pDialog.dismiss();
}
}
這是一個正確的答案 – 2012-08-18 17:38:24
耶其工作。但我還有另一個問題,我的共享意圖不會捕獲任何東西。你想讓我打開另一個問題嗎? – 2012-08-18 17:48:43