How to store Hindi text in MySQL from Android?
I get?????? in MySQL instead of Hindi text. I have the following code to get Hindi text from edittext and send to PHP page that is meant to store my text.
My activity
public class MainActivity extends Activity {
EditText s;
Button b1;
private JSONObject jsonObject=null;
List<NameValuePair> nameValuePairs;
ProgressDialog dialog = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s=(EditText)findViewById(R.id.editText1);
b1=(Button)findViewById(R.id.btn);
Typeface tf = Typeface.createFromAsset(getAssets(), "akshar.ttf");
s.setTypeface(tf);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), ""+s.getText(), Toast.LENGTH_SHORT).show();
new GetAllPosts().execute();
}
});
}
private class GetAllPosts extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0) {
ServiceHandler sh = new ServiceHandler();
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("text",""+s.getText()));
jsonObject = sh.makeServiceCall("http://192.168.24.12/temp/v1/temp.php", ServiceHandler.POST, params);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
}
+3
source to share
1 answer
Have you tried changing the encoding and collation of a MySQL table. We also use MySQL for our Android app and save text in different languages ββalong with emoticons
ALTER TABLE `student` CHANGE `student_name` `student_name` VARCHAR(50) CHARACTER SET utf8mb4 ;
utf8mb4
will work for you.
0
source to share