2017-06-22 6 views
0

私は新しいアンドロイドデベロッパーです。私はIntent.ACTION_CALLにデータを送ることができますか? 私のコードはIntent.ACTION_CALLにデータを送信できますか?

Intent callIntent = new Intent(Intent.ACTION_CALL); 
callIntent.setData(Uri.parse("tel:"+phone_number)); 
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
callIntent.putExtra("flag",1); 
context.startActivity(callIntent); 

を下回っているレシーバのアクションがandroid.intent.action.PHONE_STATEです。 BroadcastReceiverのonReceive()でフラグ値を取得するにはどうすればよいですか?

私を助けてください。

+0

私の留守を確認してください...これは変更が行わ参照放送受信機では今、この

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

ような意思を作成する一つのクラスになりました

public class example { public static boolean data; public static String strData = ""; } 

を作成してみてください@manjari –

答えて

0

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

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

    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()); 
    } 
     } 
} 
+0

私は試して、Log.e( "hi i have recieve"、example.str)を取得します。すべての発信コール – manjari

関連する問題