android添加额外的并以编程方式调用

时间:2015-05-19 07:23:16

标签: android

我试图通过我的应用程序通过提供额外的数据来打电话,但我在呼叫期间无法接收到该数据可以解释我错误的地方下面是我拨打电话和接听电话的代码

for x in glob.glob("*raw_vcf.csv"):
   csv_f = open(x, "r")

并致电接收方

String uri = "tel:"+my_name;
        Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
        callIntent.putExtra("data", "mynewdata");
        callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        _context.startActivity(callIntent);

我完全接听电话,甚至广播工作也很完美,但我没有从意图中得到数据" intent.getExtras()。getBoolean(" data")"

1 个答案:

答案 0 :(得分:1)

在这里你需要创建一个java文件(让我们把它命名为Constants.java):

public class Constants
{
 public static boolean data;
 public static String str = "";
}

现在看看我在项目中所做的更改以及评论。

String uri = "tel:"+my_name;
        Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
        Constants.data = true; /*see change, set data in Constants.data*/
        Constants.str = "some data to pass..."; /*see change*/
        callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        _context.startActivity(callIntent);

现在在广播接收器中看到所做的更改......

public class PhoneStateReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        final Bundle bundle = intent.getExtras();
        if(bundle != null && Constants.data) { /*changes done, get boolean from the Constants.data*/
            showToast("hi i have recieve");
            showToast(Constants.str); /*changes done*/
        } 

        if (intent.getAction().equals("android.intent.action.PHONE_STATE")) { 
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            Log.d(TAG,"PhoneStateReceiver**Call State=" + state);
            if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                if(recieveCall){

                }
                Log.d(TAG,"PhoneStateReceiver**Idle");
            } else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { 

            } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
            }
        } else if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { 
            // Outgoing call
            String outgoingNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Log.d(TAG,"PhoneStateReceiver **Outgoing call " + outgoingNumber);

            setResultData(null); // Kills the outgoing call

        } else {
            Log.d(TAG,"PhoneStateReceiver **unexpected intent.action=" + intent.getAction());
        }
          }
    }

希望这能解决您如何传递数据的问题