我有一個outGoingCall
廣播接收器。如何在活動結果後結束傳出呼叫?
基本上我希望它攔截任何傳出呼叫並顯示某些預定義號碼的對話框。
所以我做了這個broadcast
初始化一個activity
其中一個FragmentDialog
它初始化一個AlertDialog
。
當用戶點擊"no"
我要阻止發生的電話。
我知道setResultData(null);
在播出時應該這樣做。
但我怎樣才能將對話結果傳遞給廣播?在廣播中沒有onActivityResult()
。
我知道如何通過它,直到活動只。
fragmentDialog代碼:
public class YesNoDialogFragment extends DialogFragment {
private YesNoDialogFragmentListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
// Instantiate the NoticeDialogListener so we can send events to the
// host
mListener = (YesNoDialogFragmentListener) activity;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(activity.toString()
+ " must implement NoticeDialogListener");
}
}
這裏是我的活動代碼:
public class MainActivity extends FragmentActivity implements
YesNoDialogFragmentListener {
public static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showYesNoDialog();
}
@Override
public void onDialogPositiveClick() {
// how to send result to receiver ??
finish();
}
這裏是我的接收器代碼:
@Override
public void onReceive(final Context context, final Intent intent) {
Log.v(Constants.LOGTAG, "OutgoingCallReceiver onReceive");
if (intent.getAction()
.equals(OutgoingCallReceiver.OUTGOING_CALL_ACTION)) {
Log.v(Constants.LOGTAG,
"OutgoingCallReceiver NEW_OUTGOING_CALL received");
// get phone number from bundle
String phoneNumber = intent.getExtras().getString(
OutgoingCallReceiver.INTENT_PHONE_NUMBER);
if ((phoneNumber != null)
&& phoneNumber
.equals(OutgoingCallReceiver.ABORT_PHONE_NUMBER)) {
Toast.makeText(
context,
"NEW_OUTGOING_CALL intercepted to number 123-123-1234 - aborting call",
Toast.LENGTH_LONG).show();
Intent i = new Intent(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
SharedPreferences sharedPreferences = context
.getSharedPreferences(Constants.SHARED_PREF_NAME,
Context.MODE_PRIVATE);
boolean isBloacked = sharedPreferences.getBoolean(
Constants.IS_NUMBER_BLOCKED, true);
if (isBloacked) {
// dialog and then:
setResultData(null);
}
}
,你可以看到我試圖分享活動通過共享偏好產生結果,代碼如何是異步的,並且setResultData(null);
被稱爲bef礦石對話框顯示?
據我所知是沒有辦法來結束,除了setResultData(null);
我添加了我的代碼。你可以看到我試圖通過共享偏好來共享活動結果,代碼如何是async和setResultData(null);在顯示對話框之前調用? – 2014-12-06 21:38:08