[英]How can I trigger an event when the device's profile is changed?
I'd like to trigger an event when the user changes the phone's profile but I'm not sure how. 当用户更改手机的个人资料时,我想触发一个事件,但不确定如何。 Idealy, I could catch the a broadcast intent and know when the profile has changed but I haven't been able to find any documentation on this. 从概念上讲,我可以捕捉到广播的意图,并且知道配置文件何时更改,但是我无法找到任何相关文档。
If I'm correct, the profile system is not a part of the stock AOSP but Cyanogenmod. 如果我是对的,则概要文件系统不是股票AOSP的一部分,而是Cyanogenmod。
I've trudged through the only two profile-related classes I could find: 我在仅有的两个与概要文件相关的类中苦苦挣扎:
The only broadcast intent that I could find was here . 我唯一能找到的广播意图是在这里 。
Any idea on how this could be accomplished? 关于如何实现这一目标的任何想法? My application only targets devices running Cyanogenmod 10.1. 我的应用程序仅针对运行Cyanogenmod 10.1的设备。 This is the profile manager from CyanogenMod to give you a clearer idea of what I'm talking about. 这是CyanogenMod的配置文件管理器,用于使您更清楚地了解我在说什么。
Not sure whether i am right about what you want,but in my case it works good.Try if it can help you. 不确定我对您的要求是否正确,但就我而言,它很好用。请尝试是否可以帮助您。
I used here 2 buttons to set profile as silent and default mode.Trigger your events when those will activate upon button click. 我在这里使用了2个按钮来将配置文件设置为静音和默认模式,并在单击按钮后激活这些事件时触发您的事件。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView text = (TextView) findViewById(R.id.text1);
Button silent = (Button) findViewById(R.id.silent);
Button default = (Button) findViewById(R.id.default);
final AudioManager mode = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
silent.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
text.setText("The Mobile in Silent Mode"); //i use example case,trigger your event here
mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
Toast.makeText(getBaseContext(), "Silent Mode Activated",Toast.LENGTH_LONG).show()
}
});
default.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
text.setText("The Mobile in Default Mode"); //trigger your event here
mode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Toast.makeText(getBaseContext(), "Default Mode Activated", Toast.LENGTH_LONG).show();
}
});
}
Apparently this can also help you.. 显然,这也可以帮助您。
由于这是两个独立的环境,所以我认为现在无法检测何时从一个切换到另一个。
How can I trigger an event when the device's profile is changed? 更改设备配置文件后如何触发事件?
Android does not have any support for this , in other words you can not trigger some event while change the profile . Android对此没有任何支持,换句话说, 您无法在更改个人资料时触发某些事件。
you can only trigger event when device Ringer mode has change but not for the profile . 您只能在设备振铃器模式更改时触发事件,而配置文件则不会触发。
even i could not find the profile names of devices and current set profile name which could be the way to make what you are searching for . 即使我找不到设备的配置文件名称和当前设置的配置文件名称,也可能是您要搜索的方式。
As per my discussions with the Cyanogenmod developers, it can be handled by added a BroadcastReceiver
for the Intent
in ProfileManagerService.java
根据我与Cyanogenmod开发人员的讨论,可以通过在ProfileManagerService.java
为Intent
添加一个BroadcastReceiver
来处理它。
The issue was that this intent was missing from the ProfileManager.java
class and instead existed elsewhere. 问题是,该意图在ProfileManager.java
类中丢失,而是存在于其他位置。
The issue for this question can be found on Cyanogenmod's issue tracker . 可以在Cyanogenmod的问题跟踪器上找到此问题的问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.