我已经做了一个示例程序来进行无条件呼叫转移。此代码按照电话设置中的预期设置呼叫转移。但是我怎样才能在我的应用程序中找到它成功与否?在这里,onStart()
我正在调用startActivityForResult()
并基于 RESULT CODE 我需要执行两个不同的操作(对于 RESULT_OK 和 RESULT_CANCELLED)。这里的问题是它总是将其设置为 RESULT_CANCELLED 而不管情况如何。
public class CallForwardFragment extends Fragment {
static final int CALL_FORWARD_REQUEST = 1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.main, container,
false);
return v;
}
public void onStart() {
super.onStart();
String phoneNumber="9875678956";
String urls = "tel:" + "**21*" +phoneNumber + Uri.encode("#");
Intent intentCallForward = (new Intent(Intent.ACTION_CALL,
Uri.parse(urls)));
intentCallForward.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intentCallForward, CALL_FORWARD_REQUEST);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Toast.makeText(getActivity(), resultCode + "ResultCode",
Toast.LENGTH_SHORT).show();
if (requestCode == CALL_FORWARD_REQUEST) {
// Make sure the request was successful
if (resultCode == getActivity().RESULT_OK) {
session.enableCallForward();
session.setCallForwardNumber(callFwdPhNum);
session.setCallForwardChoice(Integer
.parseInt(ProfileDetailFragment.callFwdDetailsUtil
.getmFwdCondition()));
} else if (resultCode == getActivity().RESULT_CANCELED) {
//Always this will be called for both success and fail
Toast.makeText(getActivity(), "Cancelled", Toast.LENGTH_SHORT)
.show();
}
}
}
}