Note that there are some explanatory texts on larger screens.

plurals
  1. POOutgoing call don't start
    primarykey
    data
    text
    <p>I'm writing an application that:</p> <ol> <li><p>Intercepts an outgoing call</p></li> <li><p>Shows a dialog asking whether the call is "personal" or "business" ("Aziendale" in italian)</p></li> <li><ul> <li><strong>If "personal"</strong>, makes the call with the given number</li> <li><strong>If "business"</strong>, prepends a suffix to the number (for example 4888 - just temporarily in my code)</li> </ul></li> </ol> <p>The point is: as I don't know how to make the call wait for the user's choice, I:</p> <ol> <li><p>Close the incoming call with <code>setResultData(null)</code></p></li> <li><p>Show an alert dialog</p></li> <li><p>After user press one button make the call</p></li> </ol> <p>But, when it's time to make the call, nothing happens.</p> <p>Let me describe the classes of my application:</p> <ul> <li><p><code>MainActivity</code> (standard self-created activity for now without any function - will improve when calls work)</p></li> <li><p><code>OutgoingCallReceiver</code> (the class that extends <code>BroadcastReceiver</code> - intercept the outgoing calls)</p></li> <li><p><code>AlertActivity</code> (themed as an alert dialog, show the alert)</p></li> <li><p><code>CallActivity</code> (called by <code>AlertActivity</code> - should make the call)</p></li> </ul> <p>The manifest file is: </p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.simplecall" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /&gt; &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;receiver android:name="OutgoingCallReceiver" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.NEW_OUTGOING_CALL" /&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;activity android:name="com.example.simplecall.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.example.simplecall.AlertActivity" android:theme="@android:style/Theme.Dialog" &gt; &lt;/activity&gt; &lt;activity android:name="com.example.simplecall.CallActivity" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Here is how I coded my classes:</p> <p><strong><code>MainActivity</code>:</strong></p> <pre><code>import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { String numero; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p><strong><code>OutgoingCallReceiver</code>:</strong></p> <pre><code>import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class OutgoingCallReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub // il numero che si stava per chiamare final String numero = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); Intent in = new Intent(context,AlertActivity.class); in.putExtra("com.example.simplecall.numero", numero); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); setResultData(null); context.startActivity(in); //Toast toast = Toast.makeText(context, "Chiamata verso: " + numero, 1500); //toast.show(); } } </code></pre> <p><strong><code>AlertActivity</code>:</strong></p> <pre><code>import android.app.Activity; import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.widget.Toast; public class AlertActivity extends Activity { String numero; Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; numero = getIntent().getStringExtra("com.example.simplecall.numero"); Toast toast = Toast.makeText(this, "numero : " + numero, 5000); toast.show(); showSettingsAlert(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } /** * Mostra una finestra di dialogo * Cliccando su Impostazioni si accede al menù di configurazione * */ public void showSettingsAlert(){ AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); // Titolo della finestra alertDialog.setTitle("Tipo di chiamata"); // Mostra l'avvertimento alertDialog.setMessage("Che tipo di chiamata effettuare?"); // Cliccando su Impostazioni ... alertDialog.setPositiveButton("Aziendale", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { numero = "tel:4888"+numero; /* Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(numero)); //dialog.dismiss(); startActivity(callIntent); */ Intent in = new Intent(mContext,CallActivity.class); in.putExtra("com.example.simplecall.numero", numero); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(in); dialog.dismiss(); finish(); } }); // Cliccando su Personale alertDialog.setNegativeButton("Personale", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { numero = "tel:" + numero; /* Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(numero)); //dialog.dismiss(); startActivity(callIntent); */ Intent in = new Intent(mContext,CallActivity.class); in.putExtra("com.example.simplecall.numero", numero); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(in); dialog.dismiss(); finish(); } }); // Mostra la finestra di alert alertDialog.show(); } private void makeCall(String number, DialogInterface dial) { dial.dismiss(); try { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:"+number)); startActivity(callIntent); finish(); } catch (ActivityNotFoundException activityException) { activityException.printStackTrace(); } } } </code></pre> <p><strong><code>CallActivity</code>:</strong></p> <pre><code>import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; public class CallActivity extends Activity { String numero; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); numero = getIntent().getStringExtra("com.example.simplecall.numero"); Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse(numero)); //finish(); startActivity(callIntent); } } </code></pre> <p>But the problem is that when I instantiate <code>CallActivity</code> nothing happens ... any hints?</p> <p>I created a new "application", just for testing if i'm doing all in the correct way, same permissions in the manifest file, but it have just a standard self created activity where i perform</p> <pre><code>Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:xxx")); // xxx is a real number in the code finish(); startActivity(callIntent); </code></pre> <p>and all works fine, don't understand where i fail.</p> <p>I also noticed that if for any reason the application crash after pushing one of the two buttons(for example, if i make the call onDestroy() without calling the super.ondestroy()) , the call is correctly performed</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload