Android Fun App-SMS editor

Source: Internet
Author: User
Tags getmessage gettext

Modify the SMS database to generate text messages sent by any phone number.

Androidmanifest.xml

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.dudon.fakesms">    <uses-permissionAndroid:name= "Android.permission.READ_SMS" />    <uses-permissionAndroid:name= "Android.permission.WRITE_SMS" />    <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme">        <ActivityAndroid:name=". Mainactivity ">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>

Activity_main.xml

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal">        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "1"android:gravity= "Center"Android:text= "SMS Sender:"android:textsize= "18SP" />        <EditTextAndroid:id= "@+id/get_phone"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "7"Android:inputtype= "Phone" />    </LinearLayout>    <ScrollViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1">        <EditTextAndroid:id= "@+id/get_message"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_margin= "20DP"Android:hint= "SMS Content" />    </ScrollView>    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal">        <ButtonAndroid:id= "@+id/get_time"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "1"Android:text= "Add Current Time" />        <ButtonAndroid:id= "@+id/send_message"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"Android:layout_weight= "4"Android:text= "Send SMS" />    </LinearLayout></LinearLayout>

Mainactivity.java

 Public classMainactivityextendsappcompatactivity {Private intPhonenum; PrivateString textsms; PrivateString currenttime; PrivateButton SendMessage; PrivateButton GetTime; PrivateEditText Getphone; PrivateEditText GetMessage; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //Registering ControlsSendMessage =(Button) Findviewbyid (r.id.send_message); GetTime=(Button) Findviewbyid (r.id.get_time); Getphone=(EditText) Findviewbyid (R.id.get_phone); GetMessage=(EditText) Findviewbyid (r.id.get_message); //Get current TimeGettime.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {textsms=Getmessage.gettext (). toString (); SimpleDateFormat Formatter=NewSimpleDateFormat ("yyyy mm month dd Day hh mm min ss sec"); Date curdate=NewDate (System.currenttimemillis ());//Get current TimeCurrentTime =Formatter.format (curdate); Textsms= Textsms +currenttime;            Getmessage.settext (textsms);        }        }); //Send SMSSendmessage.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {if(Textutils.isempty (Getphone.gettext (). toString ())) {Toast.maketext (mainactivity. This, "phone number not filled in", Toast.length_short). Show (); return; }                if(Textutils.isempty (Getmessage.gettext (). toString ())) {Toast.maketext (mainactivity. This, "SMS content not filled in", Toast.length_short). Show (); return; }                //get phone numbers and SMS contentPhonenum =Integer.parseint (Getphone.gettext (). toString ()); Textsms=Getmessage.gettext (). toString (); //Turn on multithreadingThread thread =NewThread () {@Override Public voidrun () {Contentresolver resolver=Getcontentresolver (); Contentvalues Values=Newcontentvalues (); Values.put ("Address", Phonenum); Values.put ("Type", 1); Values.put ("Date", System.currenttimemillis ()); Values.put ("Body", textsms); Resolver.insert (Uri.parse ("Content://sms"), values);                }                };                Thread.Start (); Toast.maketext (mainactivity. This, "SMS successfully generated", Toast.length_short). Show ();    }        }); }}

Run:

Android Fun App-SMS editor

Related Article

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.