应用程序崩溃索尼Xperia M双(4.3)

时间:2016-03-24 10:40:14

标签: android android-volley

我创建了一个具有最小11 API和Target SDK 23 API的应用程序。我在LG Nexus4中运行应用程序,它运行正常。但我在Sony Experia M dual(4.3.3)运行相同的应用程序它崩溃了。我只有一个例外

非活动InputConnection上的ShowStatusIcon

除此之外我没有任何异常或错误。我不确定代码有什么问题,我需要做哪些更改才能在较低的API中工作。

public class Main extends AppCompatActivity implements View.OnClickListener {

RadioButton radioType,radioType1,radioType2;
RadioGroup radioGroup;
EditText FoodName,FoodLocation,ShopName;
TextView Camera,Gallery,Post;
ImageView imageView;
private Bitmap bitmap;
 private int PICK_IMAGE_REQUEST = 1;
private String UPLOAD_URL ="http://xxx.yyyy.com/volleyRegister.php";
static int TAKE_PICTURE = 1;
private String mCurrentPhotoPath;

private String KEY_IMAGE = "image";
private String KEY_NAME = "FoodName";
private String KEY_LOCATION = "FoodLocation";
private String KEY_SHOP = "ShopName";
private String KEY_TYPE = "Type";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    radioGroup = (RadioGroup)findViewById(R.id.RadioGroup);
    radioType = (RadioButton)findViewById(R.id.Online);
    radioType1 = (RadioButton)findViewById(R.id.Restaurant);
    radioType2 = (RadioButton)findViewById(R.id.StreetFood);
    FoodName = (EditText)findViewById(R.id.FoodName);
    FoodLocation = (EditText)findViewById(R.id.FoodLocation);
    ShopName = (EditText)findViewById(R.id.ShopName);
    Camera = (TextView)findViewById(R.id.Camera);
    Gallery = (TextView)findViewById(R.id.Gallery);
    Post = (TextView)findViewById(R.id.Post);
    imageView=(ImageView)findViewById(R.id.image);
    Camera.setOnClickListener(this);
    Gallery.setOnClickListener(this);
    Post.setOnClickListener(this);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
   if(v == Gallery){
        showFileChooser();
    }
    if(v == Post){
        uploadImage();
    }
    if(v == Camera){
       TakePic();
    }
}

      private void TakePic() {
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            startActivityForResult(intent, TAKE_PICTURE);
        }
    }


}

private File createImageFile() throws IOException {
    // Create an image f\ile name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  // prefix
            ".jpg",         // suffix
            storageDir      // directory
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}

private void showFileChooser() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
        Uri filePath = data.getData();
        try {
            //Getting the Bitmap from Gallery
            bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
            //Setting the Bitmap to ImageView
            imageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else{
        if(resultCode==RESULT_OK && requestCode==TAKE_PICTURE){
            try {
                bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath));
                imageView.setImageBitmap(bitmap);
            } catch (IOException e) {
                e.printStackTrace();
            }
         }}
}

 public String getStringImage(Bitmap bmp) throws UnsupportedEncodingException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG,100,baos);
    byte[] imageBytes = baos.toByteArray();
     String encodeimage =Base64.encodeToString(imageBytes, Base64.DEFAULT);


    return encodeimage;

}

   private void uploadImage(){
    //Showing the progress dialog
    final ProgressDialog loading = ProgressDialog.show(this,"Uploading...","Please wait...",false,false);
    StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                    //Disimissing the progress dialog
                    loading.dismiss();
                    //Showing toast message of the response
                    Toast.makeText(Main.this, s, Toast.LENGTH_LONG).show();

                                          }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    //Dismissing the progress dialog
                    loading.dismiss();

                    //Showing toast
                    Toast.makeText(Main.this, volleyError.getMessage(), Toast.LENGTH_LONG).show();

                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            //Converting Bitmap to String
            String rimage = null;
            try {
                rimage = getStringImage(bitmap);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            //Getting Image Name
            String FName = FoodName.getText().toString().trim();

            String FLocation = FoodLocation.getText().toString().trim();

            String SName = ShopName.getText().toString().trim();

            int selectedId = radioGroup.getCheckedRadioButtonId();
            radioType = (RadioButton)findViewById(selectedId);
            String rType = radioType.getText().toString().trim();


            //Creating parameters
            Map<String, String> params = new Hashtable<String, String>();

            //Adding parameters
           params.put(KEY_IMAGE, rimage);
            params.put(KEY_NAME, FName);
            params.put(KEY_LOCATION, FLocation);
            params.put(KEY_SHOP, SName);
            params.put(KEY_TYPE, rType);


           //returning parameters
            return params;
        }
    };

    //Creating a Request Queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    //Adding request to the queue
    requestQueue.add(stringRequest);
}
}

我使用android volley将数据发送到带有图像的SQL数据库服务器。我尝试将API更改为15,但它不起作用。请求帮助我在Sony Xperia M dual上进行改进。

日志:

C:\Users\snatarajan\AppData\Local\Android\sdk\platform-tools>adb logcat *:s     AndroidRuntime:v System.err:v
--------- beginning of main
W/System.err( 4802): com.lenovo.anyshare.dxp: Required field 'client_stats'   was not present! Struct: UALogEntry(client_stats:null, app_info:null,  device_info:null, misc_info:null)
W/System.err( 4802):    at com.lenovo.anyshare.dvn.i(SourceFile:597)
W/System.err( 4802):    at com.lenovo.anyshare.dvo.b(SourceFile:779)
W/System.err( 4802):    at com.lenovo.anyshare.dvo.b(SourceFile:1)
W/System.err( 4802):    at com.lenovo.anyshare.dvn.b(SourceFile:501)
W/System.err( 4802):    at com.lenovo.anyshare.dwv.a(SourceFile:82)
W/System.err( 4802):    at com.lenovo.anyshare.dyj.a(SourceFile:178)
W/System.err( 4802):    at com.lenovo.anyshare.dyj.c(SourceFile:142)
W/System.err( 4802):    at com.lenovo.anyshare.dyj.f(SourceFile:239)
W/System.err( 4802):    at com.lenovo.anyshare.dyj.e(SourceFile:216)
W/System.err( 4802):    at com.lenovo.anyshare.dyj.a(SourceFile:74)
W/System.err( 4802):    at com.lenovo.anyshare.dyl.a(SourceFile:42)
W/System.err( 4802):    at com.umeng.analytics.f.run(SourceFile:8)
 W/System.err( 4802):    at     java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 W/System.err( 4802):    at   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 W/System.err( 4802):    at java.lang.Thread.run(Thread.java:818)

---------系统开头

0 个答案:

没有答案