Java 无法从服务中心拨打电话

Java 无法从服务中心拨打电话,java,android,Java,Android,应用程序需要将手机拨出,并附加一些DTMF音。此电话将定期发生,需要在重新启动时启动后台服务,或启动主活动(后者主要是调试)。我已经得到了所有的许可,但我仍然不能让这一切发生 背景:手机被用作座舱(+ADK板)的远程监视器,向我发送与附加音调相关的数据,然后挂断 Android的特定版本是2.3.6,预付款ATT Fusion 2 我看过一些门票,上面说可以在通话开始时发送DTMF音,但不能在通话中发送。这很好。我不确定会有什么不同 我已经很久没有为安卓系统编程了,所以对我放松点 我收到的错

应用程序需要将手机拨出,并附加一些DTMF音。此电话将定期发生,需要在重新启动时启动后台服务,或启动主活动(后者主要是调试)。我已经得到了所有的许可,但我仍然不能让这一切发生

背景:手机被用作座舱(+ADK板)的远程监视器,向我发送与附加音调相关的数据,然后挂断

  • Android的特定版本是2.3.6,预付款ATT Fusion 2
  • 我看过一些门票,上面说可以在通话开始时发送DTMF音,但不能在通话中发送。这很好。我不确定会有什么不同

  • 我已经很久没有为安卓系统编程了,所以对我放松点

我收到的错误是:

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
CallServiceReceiver:

呼叫服务:

首先,我尝试在活动启动20秒后调用它(它将重复,但现在我将标志设置为“0”)

起始亮度:

然后,我尝试在启动20秒后从服务调用该调用(它将重复,但现在我将标志设置为“0”)

OnRestartReceiver:

清单如下所示:

<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>

有人知道这件事吗

应用程序需要将手机拨出,并附加一些DTMF音

哎呀,那是不可能的

我收到的错误是


该错误表示您没有与
意图
匹配的
服务
。这是因为您试图将
操作调用
startService()
一起使用,这是不可能的。欢迎您将
startActivity()
ACTION\u CALL
Intent
一起使用,前提是您持有
CALL\u电话
权限。

确定吗?我在票证评论线程中看到了这一点:通过调用Intent I=newintent(“android.Intent.action.CALL”、Uri.parse(“tel://“+number)),实际上可以发送DTMF音;背景。起始触觉(i);我将此方法用作解决方法,它适用于我的电信应用程序。使用逗号“,”将在音调之间发送两秒钟的延迟。@FrankLoVecchio:“你确定吗?”--如果它适用于你的一台设备,那就太好了。我不会假设所有的设备和操作系统版本都必须支持它。我也不会这样假设:)不过,我会更新代码并尝试一下。谢谢
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;
        }
    }
}
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);

    }
}
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>