0

该应用程序需要使电话拨出,并附加一些 DTMF 音调。这个电话会定期发生,需要在重启时启动后台服务,或者主活动启动(后者主要是调试)。我在阳光下获得了所有许可,但我仍然无法做到这一点。

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

  • Android 的特定版本是 2.3.6,在预付费的 ATT Fusion 2 上。
  • 我看过一些票,上面说最初可以发送 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

呼叫服务接收者:

public class CallServiceReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        Intent service = new Intent(context, CallService.class);
        context.startService(service);
    }
}

呼叫服务:

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

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

从活动开始:

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>

有人对此有见识吗?

4

1 回答 1

0

该应用程序需要使电话拨出,并附加一些 DTMF 音调。

AFAIK,这是不可能的。

我收到的错误是

该错误表明您没有ServiceIntent. 那是因为您正在尝试使用ACTION_CALLwith startService(),这是不可能的。假设您拥有权限,欢迎您startActivity()与一起使用。ACTION_CALL IntentCALL_PHONE

于 2013-06-05T21:19:36.507 回答