我是唯一一個誰可以成功上傳圖像從圖庫到在線應用程序...對於其他人來說,手機似乎在http請求崩潰,它似乎。這是我的目標還是目標?謝謝..應用程序崩潰只有一些手機(當連接到互聯網?)
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.icon2);
Bitmap bitmapOrgg = BitmapFactory.decodeFile(BrowsePicture.selectedImagePath);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
//bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
bitmapOrgg.compress(Bitmap.CompressFormat.JPEG, 30, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://asdfasdf.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
Log.d("1","1");
}
try{
Class ourClass = Class.forName("www.xxx.com");
Intent ourIntent = new Intent(upload.this, ourClass);
startActivity(ourIntent);
Log.d("2","2");
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
這是一個它崩潰的例子。但是,在另一個例子中它也崩潰了。我相信這是他們使用連接互聯網的應用程序的一部分。
它的工作原理我的手機上,但它並沒有對任何人的工作別人的(我有一個S1大火,他們已經有Nexus和銀河S4)
更新:
try{
Class ourClass = Class.forName("com.x.x.asdf.");
Intent ourIntent = new Intent(upload.this, ourClass);
startActivity(ourIntent);
Log.d("2","2");
}catch(ClassNotFoundException e){
e.printStackTrace();
}
loadSomeStuff uploader= new loadSomeStuff();
// since the first param in <Void,Void,Void> you do not send in anything in execute.
uploader.execute("test");
Log.e("LOG", BrowsePicture.selectedImagePath);
}
public class loadSomeStuff extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.icon2);
Bitmap bitmapOrgg = BitmapFactory.decodeFile(BrowsePicture.selectedImagePath);
Log.e(BrowsePicture.selectedImagePath, "yo");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
//bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
bitmapOrgg.compress(Bitmap.CompressFormat.JPEG, 30, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://website.com/php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
Log.d("1","1");
}
return "test";
}
@Override
protected void onPostExecute(String pinny){
}
}
}
你的代碼在哪裏? –
更多詳細信息添加 –
cmon請求。張貼您的logcat輸出 –