我想在我用createChooser()对话框呈现他之后检测用户选择的应用程序.所以我创建了我的BroadcastReceiver子类,如下所示:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class ShareBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context,Intent intent) {
Log.d("INFORMATION","Received intent after selection: "+intent.getExtras().toString());
}
}
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.setType("image/png");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
Log.d("INFORMATION","The current android version allow us to know what app is chosen by the user.");
Intent receiverIntent = new Intent(this,ShareBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,receiverIntent,PendingIntent.FLAG_CANCEL_CURRENT);
sendIntent = Intent.createChooser(sendIntent,"Share via...",pendingIntent.getIntentSender());
}
startActivity(sendIntent);
即使这是一个显式的PendingIntent,因为我直接使用ShareBroadcastReceiver类名而没有任何内联过滤器,我的广播接收器在用户点击选择器对话框后没有立即回调,我做错了什么?