2010-07-20 78 views
6

我有一个代码,会提示用户通过选择所需的应用程序来发送消息,我如何检测用户是否实际上已经从选项中选择或者按下了回来?如何检测用户是否从createChooser选项中选择?

我试图检查意图是否返回了某些内容,但运行异步,因此无法跟踪。

此外,我试图运行与startActivityForResult意图,我注意到onActivityResult resultCode总是0(RESULT_CANCELED),即使用户选择,或不从选择器。

回答

3

从Android的来源,你可以看到Intent中选择的Activity并不是setResult()。这应该被要求作为一个功能。

+1

反正是有知道他们已经选择哪些应用? – MinceMan 2013-05-31 13:11:15

0

您现在可以使用带有第3个参数:pendingintent.getintentsender()的新的createChooser()。

例如:

 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); 
相关问题