该应用程序需要使电话拨号出站,并附加一些DTMF音调。这个电话会定期发生,需要在重启或主要活动开始时启动后台服务(后者主要是调试)。我得到了阳光下的所有许可,但我仍然无法做到这一点。
背景:手机被用作机舱的远程监控器(+ ADK板),向我发送与所连接音调相关的数据,然后挂断。
我看过几张票据说最初可以发送DTMF音 - 但不是在通话期间。这可以。 我不确定区别是什么。
自从我为Android编程以来已经很长时间了,所以请放轻松。
我收到的错误是:
06-05 14:42:41.019: W/ActivityManager(195): Unable to start service Intent { act=android.intent.action.CALL dat=tel:xxx-xxx-xxxx flg=0x10000004 }: not found
CallServiceReceiever:
public class CallServiceReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, CallService.class);
context.startService(service);
}
}
CallService:
public class CallService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent call = new Intent(Intent.ACTION_CALL);
String number = "XXX-XXX-XXXX"; // US phone number
String tones = "1234*5678*9*1234#";
Log.i("wtf", "Dialing: " + mumber);
Log.i("wtf", "Append tones: " + tones);
call.setData(Uri.parse("tel://" + number + "," + tones));
call.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
call.addFlags(Intent.FLAG_FROM_BACKGROUND);
this.getBaseContext().startService(call);
return Service.START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
public class MyBinder extends Binder {
CallService getService() {
return CallService.this;
}
}
}
首先,我尝试在活动开始20秒后调用活动中的调用(它将重复,但我现在将标志设置为“0”)。
StartFromActivity:
public class StartFromActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AlarmManager service = (AlarmManager) this.getBaseContext()
.getSystemService(Context.ALARM_SERVICE);
Intent callServiceIntent = new Intent(this.getBaseContext(), CallServiceReceiver.class);
PendingIntent pendingCallServiceIntent = PendingIntent.getBroadcast(this.getBaseContext(), 0, callServiceIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar callServiceStart = Calendar.getInstance();
callServiceStart.add(Calendar.SECOND, 20);
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
callServiceStart.getTimeInMillis(), 0, pendingCallServiceIntent);
}
}
然后,我尝试在启动后20秒从服务中调用该调用(它将重复,但我现在将标志设置为“0”)。
OnRestartReceiver:
public class OnRestartReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
AlarmManager service = (AlarmManager) this.getBaseContext()
.getSystemService(Context.ALARM_SERVICE);
Intent callServiceIntent = new Intent(this.getBaseContext(), CallServiceReceiver.class);
PendingIntent pendingCallServiceIntent = PendingIntent.getBroadcast(this.getBaseContext(), 0, callServiceIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar callServiceStart = Calendar.getInstance();
callServiceStart.add(Calendar.SECOND, 20);
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
callServiceStart.getTimeInMillis(), 0, pendingCallServiceIntent);
}
}
清单看起来像:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name=".StartFromActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<receiver
android:name=".OnRestartReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name=".CallServiceReceiver"/>
<service android:name=".CallService"/>
</application>
有人对此有所了解吗?
答案 0 :(得分:0)
应用程序需要拨打电话拨打电话,并附加一些DTMF音。
AFAIK,这是不可能的。
我收到的错误是
错误表示您没有Service
与Intent
匹配。这是因为您尝试将ACTION_CALL
与startService()
一起使用,这是不可能的。如果您持有startActivity()
权限,欢迎使用ACTION_CALL
Intent
CALL_PHONE
。