android - Send SMS after onClick positiveButton is pressed -
a dialog box opens after "panic" button pressed. dialog box confirming presser indeed panicking.
after "yes" button pressed, want send sms number (just using mine atm)
this have far:
in main menu:
public panic panic; public void panicsos(view view) { alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("sos beacon"); builder.setmessage("are sure?"); builder.setpositivebutton("on", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { //sets panic mode panic.sendrequest(null); dialog.dismiss(); } } ); builder.setnegativebutton("off", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { //sets chill mode dialog.dismiss(); } } ); alertdialog alert = builder.create(); alert.show(); }
then in panic class
public class panic extends activity { string phonenumber = "04********"; // todo: should not static string message = "check-in request"; /** * factory method creating launch intent. * @param context * @param payload string input * @return */ public static intent makeintent(context context, string payload) { return new intent(context, panic.class); } // sends checkin request client instantly via sms public void sendrequest(view view) { smsmanager manager = smsmanager.getdefault(); manager.sendtextmessage(phonenumber, null, message, null, null); }
getting null pointer exception , few other errors. tips?
commencing gross swath of logcat grossness
09-23 02:22:22.675: d/androidruntime(4518): shutting down vm 09-23 02:22:22.675: w/dalvikvm(4518): threadid=1: thread exiting uncaught exception (group=0x41800d88)
09-23 02:22:22.675: e/androidruntime(4518): fatal exception: main
09-23 02:22:22.675: e/androidruntime(4518): process: com.illusivemen.smartwatchclient, pid: 4518
09-23 02:22:22.675: e/androidruntime(4518): java.lang.nullpointerexception
09-23 02:22:22.675: e/androidruntime(4518): @ com.illusivemen.smartwatchclient.mainmenu$2.onclick(mainmenu.java:96)
09-23 02:22:22.675: e/androidruntime(4518): @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:171)
09-23 02:22:22.675: e/androidruntime(4518): @ android.os.handler.dispatchmessage(handler.java:102)
09-23 02:22:22.675: e/androidruntime(4518): @ android.os.looper.loop(looper.java:212)
09-23 02:22:22.675: e/androidruntime(4518): @ android.app.activitythread.main(activitythread.java:5135)
09-23 02:22:22.675: e/androidruntime(4518): @ java.lang.reflect.method.invokenative(native method)
09-23 02:22:22.675: e/androidruntime(4518): @ java.lang.reflect.method.invoke(method.java:515)
09-23 02:22:22.675: e/androidruntime(4518): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:877)
09-23 02:22:22.675: e/androidruntime(4518): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:693)
09-23 02:22:22.675: e/androidruntime(4518): @ dalvik.system.nativestart.main(native method)
09-23 02:22:24.455: i/process(4518): sending signal. pid: 4518 sig: 9
09-23 02:39:04.480: d/androidruntime(5298): shutting down vm
09-23 02:39:04.480: w/dalvikvm(5298): threadid=1: thread exiting uncaught exception (group=0x41800d88)
09-23 02:39:04.490: e/androidruntime(5298): fatal exception: main
09-23 02:39:04.490: e/androidruntime(5298): process: com.illusivemen.smartwatchclient, pid: 5298
09-23 02:39:04.490: e/androidruntime(5298): java.lang.nullpointerexception
09-23 02:39:04.490: e/androidruntime(5298): @ com.illusivemen.smartwatchclient.mainmenu$2.onclick(mainmenu.java:96)
09-23 02:39:04.490: e/androidruntime(5298): @ com.android.internal.app.alertcontroller$buttonhandler.handlemessage(alertcontroller.java:171)
09-23 02:39:04.490: e/androidruntime(5298): @ android.os.handler.dispatchmessage(handler.java:102)
09-23 02:39:04.490: e/androidruntime(5298): @ android.os.looper.loop(looper.java:212)
09-23 02:39:04.490: e/androidruntime(5298): @ android.app.activitythread.main(activitythread.java:5135)
09-23 02:39:04.490: e/androidruntime(5298): @ java.lang.reflect.method.invokenative(native method)
09-23 02:39:04.490: e/androidruntime(5298): @ java.lang.reflect.method.invoke(method.java:515)
09-23 02:39:04.490: e/androidruntime(5298): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:877)
09-23 02:39:04.490: e/androidruntime(5298): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:693)
09-23 02:39:04.490: e/androidruntime(5298): @ dalvik.system.nativestart.main(native method)
09-23 02:39:05.980: i/process(5298): sending signal. pid: 5298 sig: 9
if panic
normal java class no need extend activity in it. if panic
activity instead of calling method creating object of panic
use utility class , use in both activity's as:
public class utilityclass { string phonenumber = "04********"; // todo: should not static string message = "check-in request"; public static intent makeintent(context context, string payload) { return new intent(context, panic.class); } // sends checkin request client instantly via sms public void sendrequest() { smsmanager manager = smsmanager.getdefault(); manager.sendtextmessage(phonenumber, null, message, null, null); }
now call sendrequest
alertdialog , activity as:
new utilityclass().sendrequest();
Comments
Post a Comment