Question

I am working on sms app.In my application i need to send message to recipient and after send sms it should display message and called activity i am try to display message but i didn't get succedd.I tried no of time but it is not showing.I am getting frusted now can anybody tell me what i did wrong in my code. Please solve my this issue because i cant go further step.i am attaching full source code.I am waiting for your reply.

Here is code for send Message in android

Intent smsIntent = new Intent(Intent.ACTION_VIEW);
        smsIntent.setType("vnd.android-dir/mms-sms");
        smsIntent.putExtra("address", "");
        smsIntent.putExtra("sms_body","");
        ///startActivity(smsIntent);
        startActivityForResult(smsIntent,MY_REQ_CODE);

protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        // TODO Auto-generated method stub
        //super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==MY_REQ_CODE)
        {
            if(resultCode==RESULT_OK)
            {

                broadcastIntent();
                Toast.makeText(getBaseContext(), "Message Send Successfully", Toast.LENGTH_LONG).show();
            }
        }
        else
        {
            Toast.makeText(getBaseContext(), "Message Send Successfully", Toast.LENGTH_LONG).show();
        }

    }

My receiver class

public class MyReceiver extends BroadcastReceiver
{

    @Override
    public void onReceive(Context arg0, Intent intent) 
    {
        // TODO Auto-generated method stub
        if(intent.getAction().equalsIgnoreCase("com.example.sms.CUSTOME_INTENT"))
        {
            AlertDialog.Builder alertbox = new AlertDialog.Builder(arg0);
            alertbox.setMessage("Do You want to Save?");
            alertbox.create();
            alertbox.show();
        }


    }

}

I registered receiver in manifest file

 <receiver android:name=".MyReceiver">
            <intent-filter><action android:name="com.example.sms.CUSTOME_INTENT"></action></intent-filter>
        </receiver> 
Was it helpful?

Solution

Try this way,

  runOnUiThread(new Runnable() {

    @Override
    public void run() {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top