Let me clarify it first that I am still a very amateur android developer just started about a week ago by learning from the tutorials on http://developer.android.com/training/basics/firstapp/index.html
So if my code appear to be ugly forgive me for that..
Now the actual problem – “PROGRESS DIALOG DOESN’T APPEAR” – but the rest of the code is working fine. It is sending the SMS and I am receiving them, just facing problem with PROGRESS DIALOG.
public class MainActivity extends Activity {
Context context;
public final static String EXTRA_NUMBER = "com.example.myfirstapp.NUMBER";
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
if (!isOnline()) {
Toast.makeText(MainActivity.this,"No Internet Access..Cannot Send SMS", Toast.LENGTH_LONG).show();
} else {
ProgressDialog prgDialog = ProgressDialog.show(MainActivity.this,"Free Sms","Sending SMS..Please Wait..!!",true);
EditText editTextNum = (EditText) findViewById(R.id.edit_number);
EditText editText = (EditText) findViewById(R.id.edit_message);
String number = editTextNum.getText().toString();
String message = editText.getText().toString();
try {
prgDialog.dismiss();
String msgreciever = number;
String testMessage = message;
SmsSender.sendMessage(msgreciever, testMessage);
Toast.makeText(MainActivity.this, "Message Sent Successfully",Toast.LENGTH_LONG).show();
editTextNum.setText("");
editText.setText("");
} catch (Exception ex) {
prgDialog.dismiss();
Toast.makeText(MainActivity.this, "Message Sending Failed",Toast.LENGTH_LONG).show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
}
Hello Tapan Actually You have to use the “Thread” or “Runnable” for this kind of operation… so in the “else” part of your code put this modified code which uses the Thread.. so it will definitly work for you….