Я пишу приложение, которое:Исходящий вызов не начать
перехватывает исходящий вызов
Показывает диалоговое окно с запросом вызова, является ли «личный» или «бизнес» (» Aziendale»на итальянском языке)
-
- Если "личный", делает вызов с указанным номером
- Если «бизнес», присоединяет суффикс числа (например, 4888 - просто временно в моем коде)
Суть в том, как я не знаю, как сделать ожидание вызова для выбора пользователя, I:
Закройте входящий вызов с
setResultData(null)
Показать оповещения диалоговое
После пользователя нажмите одну кнопку посылки вызова
Но, когда пришло время, чтобы сделать вызов, ничего не происходит.
Позвольте мне описать классы моего приложения:
MainActivity
(стандарт самостоятельно создали деятельности на данный момент без каких-либо функции - улучшится, когда звонки работают)OutgoingCallReceiver
(класс, который расширяетBroadcastReceiver
- перехват исходящих вызовов)AlertActivity
(в виде диалогового окна предупреждения, показать предупреждение)CallActivity
(названныйAlertActivity
- должен сделать вызов)
манифеста Файл:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.simplecall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="OutgoingCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name="com.example.simplecall.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.simplecall.AlertActivity"
android:theme="@android:style/Theme.Dialog" >
</activity>
<activity
android:name="com.example.simplecall.CallActivity" >
</activity>
</application>
</manifest>
Вот как я закодированы мои классы:
MainActivity
:
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;
}
}
OutgoingCallReceiver
:
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();
}
}
AlertActivity
:
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();
}
}
}
CallActivity
:
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);
}
}
Но проблема в том, что когда я создаю экземпляр CallActivity
, ничего не происходит ... никаких подсказок?
Я создал новый «приложение», только для тестирования, если я делаю все в правильном пути, одни и те же права доступа в файле манифеста, но есть только стандартный самостоятельной деятельности, где создал я выполнить
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:xxx")); // xxx is a real number in the code
finish();
startActivity(callIntent);
и все работает нормально, не понимаю, где я терпит неудачу.
Я также заметил, что если по какой-либо причине приложение сбой после нажатия одной из двух кнопок (например, если я вызываю вызов onDestroy() без вызова super.ondestroy()), вызов выполняется правильно
Вам не нужно CallActivity, вы должны поместить код телефонного звонка внутри нажатия кнопки. Активность предназначена только для взаимодействия с пользователем. Предлагаю вам взглянуть на: http://stackoverflow.com/questions/1556987/how-to-make-a-phone-call-in-android-and-come-back-to-my-activity -when-the-call-i –
Я тоже это пробовал, ведь в AlertActivity была прокомментированная строка, но результат, где тот же, кстати, спасибо за совет, я удалю этот класс и вернусь по старому пути (но проблема останется :() и посмотрит на вашу ссылку! – Fujitina
Проверьте свои журналы на наличие ошибок и AndroidManifest на наличие разрешений безопасности для ACTION_CALL. Erros из-за отсутствия разрешений безопасности не работает. –