前一個問題(Take screensot and save android)我發現瞭如何將文件保存到Android設備的SD卡,它工作正常。現在我需要知道如何通過名稱以編程方式查找文件,然後將文件上傳到Facebook或Twitter。目前我最大的問題是找到文件。上傳Android文件從SD卡
2
A
回答
0
3
要獲得從畫廊
String filepath; // filepath contains path of the file
public void getImage()
{
// To open up a gallery browser
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
// To handle when an image is selected from the browser, add the following to your Activity
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I'm using to hold the content:// URI of the image
Uri currImageURI = data.getData();
File file = new File(getRealPathFromURI(currImageURI));
if (file.exists())
{
filepath=file.getAbsolutePath();
}
else
{
System.out.println("File Not Found");
}
}
}
}
public String getRealPathFromURI(Uri contentUri)
{
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
文件的路徑,從SD卡
獲取圖像3210File file = new File(android.os.Environment.getExternalStorageDirectory(),"MyDraw");
if(file.exists())
{
File myfile = new File(file.getAbsoluteFile()+File.separator+"name.png");
String path = myfile.getAbsolutePath();
}
要上傳文件到服務器。我不知道如何將文件上傳到Facebook或Twitter。 一般上傳文件到服務器
public void upload(String filepath)
{
try
{
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("youe url");
File file = new File(filepath);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpeg");
mpEntity.addPart("userfile", cbFile);
httppost.setEntity(mpEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
}
catch(Exception e)
{
e.printStackTrace();
}
}
+0
我需要知道整個路徑和所有內容嗎?或者我只需要知道用戶命名圖片的內容? – James
+0
@詹姆斯你需要文件的路徑上傳圖像到服務器。該路徑將爲您提供文件表單的位置,您可以上傳相同類型的文件,以便從桌面上傳圖片。 – Raghunandan
+0
那麼我如何獲得路徑? – James
相關問題
- 1. Android:如何從SD卡上傳圖像
- 2. 從android SD卡上傳圖片到facebook
- 3. 從Android SD卡上傳文件到網絡服務器
- 4. 沒有SD卡的Android文件傳輸
- 5. 文件從SD卡
- 6. 無法在SD卡上寫文件android
- 7. 在Android上寫文件到SD卡(lost.dir)
- 8. 在SD卡上製作文件夾android
- 9. 訪問SD卡上的文件android
- 10. 從android中的SD卡打開文件?
- 11. android從sd卡讀取文件
- 12. Android SD卡文件系統
- 13. 意圖從SD卡上的文件播放Android上的視頻
- 14. 從SD卡讀取文件
- 15. 從Facebook上的SD卡上傳圖片Android
- 16. 估算在Android上從SD卡讀取大文件的時間
- 17. 打開從SD卡上的文件在android系統
- 18. 掃描QR碼從SD卡上的圖像文件在android
- 19. 使用'FileWriter'在Android上的SD卡上寫入文本文件
- 20. Android NFC,SD卡上的安全元件
- 21. Android:從SD卡ViewPager圖庫
- 22. 如何將SD卡上的文件上傳到Arduino網頁
- 23. 如何將SD卡上的3gp文件上傳到服務器?
- 24. Android中的SD卡文件瀏覽器
- 25. Android:將文件保存到SD卡?
- 26. Android:將文件保存到SD卡
- 27. 將RAW文件到SD卡中的Android
- 28. Android:將文件保存到SD卡
- 29. 將文件寫入Android SD卡
- 30. 引用Android上的SD卡上的文件
我該如何得到路徑? – James
@james你需要從圖庫中獲取圖片嗎?或者你需要從OT的情況下,你知道文件名 – Raghunandan
SD卡獲取圖像,我相信這樣是 – James