开发者

How can I detect if user selected from createChooser options?

I have a code that will prompt user to send a message by selecting the desired application, how can I detect if the user actually have chose from the options or instead pressed Back?

I tried to check if the intent returned something, 开发者_StackOverflow中文版but is running asyncronous so cannot be tracked.

Also I have tried to run the intent with startActivityForResult, what I noticed in onActivityResult that resultCode is always 0(RESULT_CANCELED) even if user selected, or not from the chooser.


From Android's source, you can see that the Activity that chooses among Intents doesn't setResult() at all. That should be requested as a feature.


you can now use the new createChooser() with 3rd arg: pendingintent.getintentsender().

example:

        String aText = e.getText().toString();
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, aText);
        sendIntent.setType("text/plain");
        sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        sendIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

        //
        Intent receiver = new Intent(this, BroadcastTest.class);
        receiver.putExtra("test", "test");
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
        Intent intent = Intent.createChooser(sendIntent, "Send email with:", pendingIntent.getIntentSender());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜