Code Snippets

This is a discussion on Code Snippets within the LG Ally Hacking / Development forums, part of the LG Ally category; The following code is used to change the behavior of the soft back button. @Override public void onBackPressed() { Toast. makeText ( this , "The ...

Results 1 to 2 of 2

Thread: Code Snippets

  1. #1
    Android Junkie allyAndroid's Avatar
    Join Date
    Jun 2010
    Location
    Ohio
    Posts
    1,413
    The following code is used to change the behavior of the soft back button.



    @Override


    publicvoid onBackPressed() {


    Toast.makeText(
    this, "The back button was pressed.", Toast.LENGTH_LONG).show();


    return;


    }




    Motorola Droid 4

  2. Android.net is the premier Android Forum. Registered users do not see these ads. .

  3. #2
    Android Junkie allyAndroid's Avatar
    Join Date
    Jun 2010
    Location
    Ohio
    Posts
    1,413
    The following code can be used to send some text to the default messaging app.



    private EditText userText;

    private EditText userPhone;



    private void sendSMS(String phoneNo, String message) {

    String inputText = userText.getText().toString();

    String inputNumber = userPhone.getText().toString();



    Intent sendIntent = new Intent(Intent.ACTION_VIEW);

    sendIntent.putExtra("sms_body", inputText);

    sendIntent.putExtra("address", inputNumber);

    sendIntent.setType("vnd.android-dir/mms-sms");



    startActivity(sendIntent);

    }



    The following code can be used when you want to send the text to someone without using the default messaging app:



    private EditText userText;

    private EditText userPhone;



    private void sendSMS(String phoneNo, String message) {

    String inputText = userText.getText().toString();

    String inputNumber = userPhone.getText().toString();



    SmsManager sms = SmsManager.getDefault();

    sms.sendTextMessage(inputNumber, null, inputText, null, null);

    Toast.makeText(getBaseContext(), "Message has been sent.", Toast.LENGTH_LONG).show();

    }



    The second method requires you to add permissions to send text messages.



    Motorola Droid 4

Remove Ads

http://www.scramblerducati.org/

Sponsored Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

android code snippets

,
android public void onbackpressed()
,
android search snippet
Click on a term to search our sites for related topics.
Android Forum