I'm trying to send a message from my app using as SMS content the content of a editText. I tryed in this way so far:
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
String content = edit.getText().toString();
it.putExtra("sms_body", content);
startActivity(it);
but when the activity starts there is no content in the message.. isn't possible do something like that?
Try to send message like this
String phoneNo = "080000123";
String sms = textsms.getText().toString();
try
{
android.telephony.SmsManager smsmanager = android.telephony.SmsManager.getDefault();
smsmanager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(),"SMS faild, please try again later!",Toast.LENGTH_LONG).show();
e.printStackTrace();
}
I tried using the same code of yours, but within a method call. This is because if you have more than 1 messaging app installed on your device you will have to manually select the app that you are going to send your message with.
In my case I have whatsapp, messaging, etc. So having your code in the onCreate(), it will only fail as there is no option selected by the user...But when I have this code within a method body and I trigger with a button or any other even similarly, it works fine(only thing is you will have to select the app-you can make any of the app as default so that the next time you don't have to do this manually).
My MainActivity.java
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void send(View v)
{
Uri uri = Uri.parse("smsto:9999999999");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
EditText edit = (EditText) findViewById(R.id.editText1);
String content = edit.getText().toString();
it.putExtra("sms_body", content);
startActivity(it);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
My activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="send" />
</LinearLayout>
Related
I'm trying to display a persistent message at the bottom of my application(through out all activities) when there's no internet connection, and the message disappears once there's a network connection
I thought about using and application dialog, which I was able to do, but then I realised the background was not clickable, I need users to still have access to navigate pages/menu
something as seen in the picture below
What I tried with a custom alert dialog
NoInternetDialog.java
public class NoConnectionDialog {
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.no_internet_connection_dialog);
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.gravity = Gravity.BOTTOM;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
// Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
// dialogButton.setOnClickListener(new View.OnClickListener() {
// #Override
// public void onClick(View v) {
// dialog.dismiss();
// }
// });
dialog.show();
}
}
the XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/zxing_viewfinder_laser"
android:elevation="4dp"
android:orientation="vertical"
android:padding="#dimen/_8sdp"
app:elevation="4dp">
<TextView
android:id="#+id/text_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/no_internet_connection"
android:textColor="#color/colorWhite"
android:textSize="#dimen/dimen_16" />
</LinearLayout>
and how I call it
NoConnectionDialog alert = new NoConnectionDialog();
alert.showDialog(this, "No Internet Connection");
What do you guys suggest?
Don't use a Dialog, just add that layout to your Activity's layout and set the visibility based on whether the user has an internet connection. This will avoid all of the issues you'll run into trying to do this with a Dialog. If you have multiple Activitys, you could use a common superclass for them that includes this functionality.
I am working with an application that involves to dialog boxes that should appear one after the other. What I mean is that, when I click on the positive button of the first dialog box it should then bring up another second dialog box. The issue I am facing is with the second dialog box, the second one will not pop up and it causes the application to crash.
I get an error that says "java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first."
public static void showBusinessOrPrivateStartDialog(final Context context, final CallLogEntry call)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
// If new version of android, then check permission
if (!Settings.canDrawOverlays(context))
{
Log.e(TAG, "Permission Denied: Draw overlays (for popup)");
return;
}
}
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//View view = inflater.inflate(R.layout.dialog_call_type, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context, Theme_Material_Light_Dialog_Alert);
builder.setTitle("Was this a private or a business call?");
builder.setMessage("Please select a call type");
builder.setIcon(R.drawable.ic_deviceinsight);
builder.setCancelable(true);
//builder.setView(view);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
#Override
public void onCancel(DialogInterface dialog) {
// Occurs when user cancels the dialog, or clicks somewhere else in the screen or presses the back button
Log.i(TAG, "cancelled");
saveCallEntry(context, call, CLASSIFICATION_TYPE_BUSINESS, "", true, "");
}
});
builder.setPositiveButton("Business", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
CallClassification.showBusinessCallPopup(context, call);
}
});
builder.setNegativeButton("Private", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
saveCallEntry(context, call, CLASSIFICATION_TYPE_PRIVATE, "", false, "");
}
});
AlertDialog dialog = builder.create();
// Rather use something like TYPE_SYSTEM_ALERT, if possible.
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); // TYPE_SYSTEM_ERROR
dialog.show();
}
This is the second method for the second dialog box and my app crashes on dialog.show
public static void showBusinessCallPopup(final Context context, final CallLogEntry call)
{
// NEW NRF
if (AppPreferences.isNRF(context)) {
CallItem callItem = saveCallEntry(context, call, CLASSIFICATION_TYPE_BUSINESS, "", false, "");
// SHOW NEW FORM
Intent intent = new Intent(context, CallClassificationFormActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
EventBus.getDefault().postSticky(callItem);
context.startActivity(intent);
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
// If new version of android, then check permission
if (!Settings.canDrawOverlays(context))
{
Log.e(TAG, "Permission Denied: Draw overlays (for popup)");
return;
}
}
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.dialog_call_details, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context, Theme_Material_Light_Dialog_Alert);
String toOrFrom = call.Type == CallLog.Calls.INCOMING_TYPE ? "from" : "to";
//builder.setTitle("Business call");
builder.setCustomTitle(view);
//builder.setMessage("Please enter reference details for the call " + toOrFrom + " " + call.Number);
//builder.setIcon(R.drawable.ic_deviceinsight);
builder.setCancelable(true);
builder.setView(view);
final EditText etReference = (EditText)view.findViewById(R.id.etReference);
final EditText etComment = (EditText)view.findViewById(R.id.etComment);
builder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String reference = etReference.getText().toString();
String comment = etComment.getText().toString();
saveCallEntry(context, call, CLASSIFICATION_TYPE_BUSINESS, reference, false, comment);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
#Override
public void onCancel(DialogInterface dialog) {
Log.i(TAG, "cancelled");
}
});
AlertDialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); // TYPE_SYSTEM_ERROR
dialog.show();
}
and here is my xml. I have included the xml in this post because I read somewhere that the way the height and width of my textboxes is defined
might be causing an issue.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
tools:context=".calls.CallClassification">
<TextView
android:id="#+id/tvMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:padding="5dp"
android:text="Please enter reference details for the call "
android:textColor="#color/colorPrimaryDark"
android:textSize="16sp"/>
<AutoCompleteTextView
android:id="#+id/etReference"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorAccent"
android:hint="Matter Code *"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLength="255"
android:text=""
android:textColor="#color/colorPrimary"
android:textColorHint="#color/colorTextHint"
android:textSize="14sp"/>
<CheckBox
android:id="#+id/cbBillable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:button="#null"
android:buttonTint="#color/colorAccent"
android:checked="true"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text="Billable"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"/>
<EditText
android:id="#+id/etComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorAccent"
android:hint="Enter comment"
android:imeOptions="actionDone"
android:inputType="text"
android:lines="1"
android:maxLength="1000"
android:maxLines="4"
android:minLines="1"
android:text=""
android:textColor="#color/colorPrimary"
android:textColorHint="#color/colorTextHint"
android:textSize="14sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/bCancel"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"/>
<Button
android:id="#+id/bOk"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GO"/>
</LinearLayout>
</LinearLayout>
After hearing to your experience, I could think of one more solution. Rather than declaring AlertDialog variable inside each of the methods, declare one global variable so that you can make sure that only one Dialog is shown at any instance.
While declaring, make
AlertDialog dialog = null;
in class
Then in,
showBusinessOrPrivateStartDialog() {
if(dialog == null) {
dialog = build.create();
}
}
builder.setPositiveButton("Business", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
CallClassification.showBusinessCallPopup(context, call);
}
});
builder.setOnDismissListener(new OnDismissListener() {
public void onDismiss() {
dialog = null;
}
}
Then again in showBusinessCallPopup(),
if(dialog == null) {
dialog = build.create();
}
Hope this helps you.
Before calling
CallClassification.showBusinessCallPopup(context, call);
you need to call
dialog.dismiss();
within the same onClick().
Hope this solves your case.
In your second code you are adding view twice, maybe you should remove one of them.
builder.setCustomTitle(view); -> Here
builder.setCancelable(true);
builder.setView(view); --> Here
:)
In android,i want to get a string from user using EditText and on click of submit button the string need to be show on another page/pane.
here is my fragment.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText android:id="#+id/msg"
android:hint="#string/entertheip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text"
/>
<Button android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Button1"
/>
<TextView android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/thetext"
android:visibility="invisible"
/>
</LinearLayout>
and corresponding java class is this
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
Button bu = (Button)findViewById(R.id.button1);
bu.setOnClickListener(new View.OnClickListener() {
private TextView tv = (TextView)findViewById(R.id.tv);
#Override
public void onClick(View v) {
// to view the ip in another page
try{
EditText et = (EditText)findViewById(R.id.msg);
String t = et.getText().toString();
tv.setText(t);
}catch(NullPointerException e){
e.printStackTrace();
}
}
});
}
}
But i am getting the Edit Text and Button only, the text is not showing in another page. Kindly help in this.
place this inside onClick
tv.setVisibility(View.VISIBLE);
You will have to use an Intent to go to another activity, like
Intent i=new Intent(MainActivity.this, someClass.class);
startActivity(i);
save the string in app preference and use the preference tag in that class and set the string to some textview you want there ...
try below way:-
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
Button bu = (Button)findViewById(R.id.button1);
TextView tv = (TextView)findViewById(R.id.tv);
EditText et = (EditText)findViewById(R.id.msg);
bu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// to view the ip in another page
try{
String t = et.getText().toString();
tv.setText(t);
}catch(NullPointerException e){
e.printStackTrace();
}
}
});
}
Remove this line from TextView tag of your XML File:-
android:visibility="invisible"
You can navigate between activities using Intent and also pass data with it
Using Intents to Create Flows
Simple way on your case is
On Button click
Intent i = new Intent(MainActivity.this, ActivityTwo.class);
i.putExtra("username", "foobar");
startActivity(i); // brings up the second activity
On Another Activity
// ActivityTwo.java (subactivity) can access any extras passed in
protected void onCreate(Bundle savedInstanceState) {
String username = getIntent().getStringExtra("username");
}
You have not added onClick to button: Fix that.
<Button android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Button1"
android:onClick="onBtnClick"
/>
And you need not override onClick if you are not implementing onClickListener in activity.
public void onBtnClick(View v) {
// to view the ip in another page
try{
EditText et = (EditText)findViewById(R.id.msg);
String t = et.getText().toString();
tv.setText(t);
tv.setVisibility(View.VISIBLE); //as you have kept visibility invisible in xml
}catch(NullPointerException e){
e.printStackTrace();
}
}
Hope it helps.
The application now is crashing due to nullpointerexception. I have found many different similar problems on google, however, none of the solutions worked. This app is supposed to forward a call, where the number to receive the forwarded calls are stored within the shared preferences. As for the numbers to forward are stored within a database. If possible, do guide me on how to get data from the database as well. Thanks
These are the logcats:
02-12 15:09:07.745: E/AndroidRuntime(4827): Caused by: java.lang.NullPointerException
02-12 15:09:07.745: E/AndroidRuntime(4827): at com.example.awkwardpanda_redirectcall.MainActivity.onCreate(MainActivity.java:33)
02-12 15:09:07.745: E/AndroidRuntime(4827): at android.app.Activity.performCreate(Activity.java:5158)
02-12 15:09:07.745: E/AndroidRuntime(4827): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-12 15:09:07.745: E/AndroidRuntime(4827): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
02-12 15:09:07.745: E/AndroidRuntime(4827): ... 11 more
This is my mainactivity.java
public class MainActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Switch switch1 = (Switch) findViewById(R.id.switch1);
EditText editText1 = (EditText) findViewById(R.id.editText1);
SharedPreferences preferences;
preferences = PreferenceManager.getDefaultSharedPreferences(this);
final String streditText1 = preferences.getString("Number", "");
editText1.setText(streditText1);
// set the switch to OFF
switch1.setChecked(false);
// attach a listener to check for changes in state
switch1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Toast.makeText(getApplicationContext(), "Call Forwarding is activated",Toast.LENGTH_SHORT).show();
callforward("*63*" + streditText1 + "#"); // 0123456789 is the number you want to forward the calls.;
}
else{
Toast.makeText(getApplicationContext(), "Call Forwarding is deactivated",Toast.LENGTH_SHORT).show();
callforward("#81#");
}
}
});}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void manage_numbers_onClick(View view) {
Intent myIntent = new Intent(this, Manage_numbers.class);
startActivity(myIntent);
}
private void callforward(String ArrayString)
{
//DBAdapter db = new DBAdapter(this);
//db.getAllContacts().toString();
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager)
this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Intent intentCallForward = new Intent(Intent.ACTION_CALL);
Uri mmiCode = Uri.fromParts("tel", ArrayString, "#");
intentCallForward.setData(mmiCode);
startActivity(intentCallForward);
}
private class PhoneCallListener extends PhoneStateListener
{
private boolean isPhoneCalling = false;
#Override
public void onCallStateChanged(int state, String incomingNumber)
{
if (TelephonyManager.CALL_STATE_RINGING == state)
{
// phone ringing
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state)
{
// active
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state)
{
// run when class initial and phone call ended, need detect flag
// from CALL_STATE_OFFHOOK
if (isPhoneCalling)
{
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
}
}
}
}
This is my xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="#string/checktoconfirm"/>
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:inputType="phone"
android:text="#string/receivenumbertext" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="10dp"
android:text="#string/savebtn" />
</LinearLayout>
I see no #+id/switch1 in your layout; findViewById() will return null.
UPD: You probably would like to read Re-using Layouts with <include/>
Probably the value of "editText1" is Null which is causing the crash. Check and fix it to incluidng it properly in xml & referncing in the code to remove the crash
I am developing an application using sms, my requirement is 1) send sms with static values 2)whenever we click on edit button we can change values and send sms , I can do both of them successfully but my third requirement is to send sms only when click on edit and change values click on submit buttons, without change value I do not want send sms. I want when click on edit button then only send sms, i tried with if(editBtn.isSelected) but it is not working. please tell any solution
my code is
xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical" >
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editBtn"
android:text="EDIT"
android:textColor="#00FF00"
android:onClick="editListener"/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NUMBER"
android:textSize="20dip"/>
<EditText android:layout_width="150dip"
android:layout_height="wrap_content"
android:id="#+id/numberEdit"
android:text="8989897979"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MESSAGE"
android:textSize="20dip"/>
<EditText android:layout_width="150dip"
android:layout_height="wrap_content"
android:id="#+id/messageEdit"
android:text="HAI HOW R U"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/subBtn"
android:text="SUBMIT"/>
</LinearLayout>
Activty
public class MainActivity extends Activity {
private EditText contactEdit;
private EditText messageEdit;
private Button submitBtn;
private Button editBtn;
String contact;
String message;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
contactEdit = (EditText)findViewById(R.id.numberEdit);
messageEdit = (EditText)findViewById(R.id.messageEdit);
submitBtn = (Button)findViewById(R.id.subBtn);
editBtn = (Button)findViewById(R.id.editBtn);
if(editBtn.isSelected()){
submitBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
contact = contactEdit.getText().toString();
message = messageEdit.getText().toString();
try{
SmsManager manger = SmsManager.getDefault();
manger.sendTextMessage(contact, null, message, null,
null);
Toast.makeText(getApplicationContext(), "SMS SENT",
100).show();
}
catch(Exception e){
Toast.makeText(getApplicationContext(), "SMS NOT
SEND", 100).show();
e.printStackTrace();
}
}
});
}
else {
Toast.makeText(getApplicationContext(), "NOT EDITED", 100).show();
}
editBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
changeEdit();
}
});
}
private void changeEdit(){
contactEdit.setClickable(true);
contactEdit.setCursorVisible(true);
contactEdit.setFocusable(true);
contactEdit.setFocusableInTouchMode(true);
messageEdit.setClickable(true);
messageEdit.setCursorVisible(true);
messageEdit.setFocusable(true);
messageEdit.setFocusableInTouchMode(true);
}
}
Try to use OnTouchListener for the edittext
sample,
editBtn.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
changeEdit();
return true;
}
});
if its not working
Create a boolean variable Globally and make it true if u touched onto the edittext,
//In grobal
boolean e_clicked = false;
//Inside the Edittext onTouchListener
e_clicked=true;
and check
if(e_clicked)
{
// your sms send action
}
try this
public class AlarmReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
#Override
public void onReceive(Context context, Intent intent) {
Intent intent=new Intent(context,Service.class);
//get lat/lng and pass it or get from service if u want
intent.putExtra("lat","lat");
intent.putExtra("lon","lng");
context.startService(intent);
}
}
public void SetAlarm(Context context) {
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MINUTE, 10);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
calendar.getTimeInMillis(), pi);
}