A:OnActivityResult no se genera

I wrote this code to picking a sms messags. i want to open converssation list and then picking a sms message to display it on an textview control. to do this goal i call an intent to opening conversation list activity. conversation list is opened successfully but when i selecting a sms message no action is occured. when i traced my app, i understood that when i am selecting a sms message, onActivityResult is not raised but when i am returning to my app this method is raised. i do know what can i do to solve this problem?

the proposed code to this goal is here:

private static final int PICK_SMS_MESSAGE=1;
    private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button b=(Button) findViewById(R.id.btnPickSMS);
        b.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Uri uri=Uri.parse("content://mms-sms/conversations");
                Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setClassName("com.android.mms", "com.android.mms.ui.ConversationList");
                //intent.setType("vnd.android-dir/mms-sms");
                intent.setDataAndType(uri,"vnd.android-dir/mms-sms" );
                Log.i("Log","Start");
                startActivityForResult(intent, PICK_SMS_MESSAGE);
            }
        });

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.i("Log","Point2");
        if(resultCode==RESULT_OK)
        {
            Log.i("Log","Point3");
            if(requestCode==PICK_SMS_MESSAGE)
            {
                //Uri smsUri=data.getData();
                //tv.setText();
                Bundle bundle=data.getExtras();
                Log.i("Log","Point4");
                if(bundle!=null)
                {
                    Object[] pdus=(Object[]) bundle.get("pdus");
                    for(Object o : pdus)
                    {
                        SmsMessage messages=SmsMessage.createFromPdu((byte[]) o);
                        tv.setText(messages.getDisplayMessageBody());
                        Log.i("Log","Point5");
                    }
                }
            }
        }
        //finish();
        super.onActivityResult(requestCode, resultCode, data);
    }

preguntado el 27 de noviembre de 13 a las 07:11

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.