Android (java) Learning note 99:android SMS transmitter Research

Source: Internet
Author: User
<span id="Label3"></p><p><p>1. The first type of SMS program can be called inside the System.</p></p><p><p></p></p><p><p>I have previously appeared a bug is an error:</p></p><p><p></p></p><p><p>Android.content.ActivityNotFoundException:No Activity found to handle Intent {act=android.intent.action.sendto dat= tel:xxx} ...</p></p><p><p>This is because I use the intent call system editing text message service parameters are not set, after carefully check the changes, changed to look like this is no problem:</p></p><p><p>The reason for this error is:</p></p><p><p>The code before I called intent to start the activity is:</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #0000ff;">New</span> Intent (intent.action_sendto,uri.parse ("sms:" +message); <span style="color: #008080;"> 2</span> startactivity (intent);</pre></pre><p><p>It is not possible to call this constructor here, we go back to see the API and Find:</p></p><p><p><code><strong>Intent</strong>(String action, Uri uri)</code><br>Create an intent with a given action and for <strong><span style="color: #ff0000;">a given data URL</span></strong>. (this requirement is a given, that is, a constant), which means that the constructor parameter cannot be a variable</p></p><p><p><span style="color: #ff0000;"><strong>(concrete method entity, can go to see Api)</strong></span></p></p><p><p><strong>the following uses intent to invoke the SMS editor inside the system</strong> :</p></p><pre><pre>1 Intent Intent = new<span><span>intent.setaction (intent.action_sendto), 3 intent.setdata (uri.parse ("smsto:" +<span>num)); 4 Intent.putextra ("sms_body"<span>, message); 5 startactivity (intent); </span> </span> </span></span></pre></pre><p><p></p></p><p><p></p></p><p><p>Click: send a text message, the program will actively re-jump to the following interface, is called the Android system inside the SMS editing program</p></p><p><p></p></p><p><p></p></p><p><p>2. That is, we do not call the Android system SMS editor program, but write their own text message editing Program: (the program part of the important code is as follows):</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>Sendmess_button.setonclicklistener (<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">View.onclicklistener () {</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">OnClick (View V) {</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>String str2 = "";<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Remember that this can only be defined as "", null character, before I was defined as null, always can not eject send content is empty hint</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span>String num =<span style="color: #000000;"><span style="color: #000000;">edit_num.gettext (). toString ();</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span>String message =<span style="color: #000000;"><span style="color: #000000;">edit_mess.gettext (). toString ();</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span>Smsmanager Smsmanager =<span style="color: #000000;"><span style="color: #000000;">Smsmanager.getdefault ();</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span>Arraylist<string> texts=<span style="color: #000000;"><span style="color: #000000;">smsmanager.dividemessage (message);//split sms, multi-word message split into multiple SMS</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(message.equals (str2) | |<span style="color: #000000;"><span style="color: #000000;">num.equals (str2)) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>Toast.maketext (mainactivity.<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">. Getapplicationcontext (),</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>"you're a erlengzi, you haven't entered a text message or entered a mobile phone number," 1<span style="color: #000000;"><span style="color: #000000;">). Show ();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Intent Intent = new Intent ();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">intent.setaction (intent.action_sendto);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">intent.setdata (uri.parse ("smsto:" +num));</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Intent.putextra ("sms_body", message);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">startactivity (intent);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span><span style="color: #000000;"><span style="color: #000000;">(String text:texts) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>Smsmanager.sendtextmessage (num,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>, text,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> at</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>});</pre><p><p></p></p><p><p></p></p><p><p>After that I also encountered intent call dialing with corresponding error:</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>06-04 04:09:24.285:W/DALVIKVM (12398): Threadid=1:thread exiting with uncaught exception (group=0x40a71930<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span>06-04 04:09:24.326:e/androidruntime (12398<span style="color: #000000;"><span style="color: #000000;">): FATAL Exception:main</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span>06-04 04:09:24.326:e/androidruntime (12398):<span style="color: #ff0000;"><span style="color: #ff0000;"><strong>android.content.ActivityNotFoundException:No Activity found to handle Intent {act=android.intent.action.call dat= tel:xxx}</strong></span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span>06-04 04:09:24.326:e/androidruntime (12398): at Android.app.Instrumentation.checkStartActivityResult ( instrumentation.java:1622<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>06-04 04:09:24.326:e/androidruntime (12398): at Android.app.Instrumentation.execStartActivity (instrumentation.java : 1417<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span>06-04 04:09:24.326:e/androidruntime (12398): at Android.app.Activity.startActivityForResult (activity.java:3370<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span>06-04 04:09:24.326:e/androidruntime (12398): at Android.app.Activity.startActivityForResult (activity.java:3331<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span>06-04 04:09:24.326:e/androidruntime (12398): at Android.app.Activity.startActivity (activity.java:3566<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span>06-04 04:09:24.326:e/androidruntime (12398): at Android.app.Activity.startActivity (activity.java:3534<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span>06-04 04:09:24.326:e/androidruntime (12398): at Com.himi.sendmessage.mainactivity$1.onclick (MainActivity.java:47<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span>06-04 04:09:24.326:e/androidruntime (12398): at Android.view.View.performClick (view.java:4204<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>06-04 04:09:24.326:e/androidruntime (12398): at Android.view.view$performclick.run (view.java:17355<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>06-04 04:09:24.326:e/androidruntime (12398): at Android.os.Handler.handleCallback (handler.java:725<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>06-04 04:09:24.326:e/androidruntime (12398): at Android.os.Handler.dispatchMessage (handler.java:92<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span>06-04 04:09:24.326:e/androidruntime (12398): at Android.os.Looper.loop (looper.java:137<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>06-04 04:09:24.326:e/androidruntime (12398): at Android.app.ActivityThread.main (activitythread.java:5041<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>06-04 04:09:24.326:e/androidruntime (12398<span style="color: #000000;"><span style="color: #000000;">): at java.lang.reflect.Method.invokeNative (Native METHOD)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>06-04 04:09:24.326:e/androidruntime (12398): at Java.lang.reflect.Method.invoke (method.java:511<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span>06-04 04:09:24.326:e/androidruntime (12398): at Com.android.internal.os.zygoteinit$methodandargscaller.run ( zygoteinit.java:793<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>06-04 04:09:24.326:e/androidruntime (12398): at Com.android.internal.os.ZygoteInit.main (zygoteinit.java:560<span style="color: #000000;"><span style="color: #000000;">)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span>06-04 04:09:24.326:e/androidruntime (12398<span style="color: #000000;"><span style="color: #000000;">): at Dalvik.system.NativeStart.main (Native METHOD)</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>06-04 04:09:26.744:i/process (12398): Sending Signal. pid:12398 Sig:9</pre><p><p>This is the same as the above text message problem, or the basic concept is not solid</p></p><p><p>Android (java) Learning note 99:android SMS transmitter Research</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.