模拟接听电话时的振动

发布于 2024-08-22 03:41:46 字数 106 浏览 7 评论 0原文

所以我试图模拟手机正在接听电话。我已成功提取手机铃声并播放。现在我想模拟振动。虽然我可以让手机振动,但我想模拟手机接到电话时振动的确切模式。是否有一些设置或类可以用来提取此模式,并检测振动是否打开?

So I am trying to simulate that the phone is receiving a call. I have successfully extracted the phones ring tone and played it. Now I want to simulate the vibration. While I can make the phone vibrate, I want to emulate the exact pattern that the phone vibrates with as when it receives a call. Is there some setting or class that I can use to extract this pattern, and also detect if vibration is turned on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橪书 2024-08-29 03:41:46

你必须以某种模式振动它。

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);  

// 1. Vibrate for 1000 milliseconds  
long milliseconds = 1000;  
v.vibrate(milliseconds);  

// 2. Vibrate in a Pattern with 500ms on, 500ms off for 5 times  
long[] pattern = { 500, 300 };  
v.vibrate(pattern, 5);

http://www.androidsnippets.org/snippets/22/

我不确定使用什么模式作为标准,您可能可以在源代码中找到它,或者自己继续尝试不同的模式,直到满意为止。

You have to vibrate it in a pattern.

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);  

// 1. Vibrate for 1000 milliseconds  
long milliseconds = 1000;  
v.vibrate(milliseconds);  

// 2. Vibrate in a Pattern with 500ms on, 500ms off for 5 times  
long[] pattern = { 500, 300 };  
v.vibrate(pattern, 5);

http://www.androidsnippets.org/snippets/22/

I'm not sure what pattern is used as standard, you could probably find it in the source, or else keep trying different patterns yourself until it is satisfactory.

傻比既视感 2024-08-29 03:41:46

似乎没有类可以为您提供来电的“标准”振动设置。
由于大多数手机都配有自定义供应商呼叫者应用程序,并且 Google Play 上有很多自定义呼叫者应用程序,因此这种“标准”模式可能根本不存在。

AOSP 的标准来电应用程序使用此模式:

private static final int VIBRATE_LENGTH = 1000; // ms
private static final int PAUSE_LENGTH = 1000; // ms

并检测是否打开振动:

boolean shouldVibrate() {
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = audioManager.getRingerMode();
    if (Settings.System.getInt(mContext.getContentResolver(), "vibrate_when_ringing", 0) > 0) {
        return ringerMode != AudioManager.RINGER_MODE_SILENT;
    } else {
        return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
    }
}

这依赖于您可以在标准手机设置中找到的“响铃时振动”和“声音模式”设置。

It seems like there is no class that can provide you with 'standart' vibration settings for incoming call.
Since most phones come with custom vendor caller apps and since there are a lot of custom caller apps on Google Play, this 'standart' pattern probably doesn't even exist.

Standart caller app from AOSP uses this pattern:

private static final int VIBRATE_LENGTH = 1000; // ms
private static final int PAUSE_LENGTH = 1000; // ms

And to detect if the vibration is turned on:

boolean shouldVibrate() {
    AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    int ringerMode = audioManager.getRingerMode();
    if (Settings.System.getInt(mContext.getContentResolver(), "vibrate_when_ringing", 0) > 0) {
        return ringerMode != AudioManager.RINGER_MODE_SILENT;
    } else {
        return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
    }
}

This relies on the "Vibrate while ringing" and "Sound mode" settings you can find in standart phone settings.

长伴 2024-08-29 03:41:46

为什么不使用 Android 源代码来看看他们是如何做到的呢?

电话应用程序源代码可从
获取
https://android.googlesource.com/platform/packages/apps/Phone

Why not use the Android source in order to see how they do it?

The Phone app source is available from
https://android.googlesource.com/platform/packages/apps/Phone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文