简体   繁体   English

更改设备配置文件后如何触发事件?

[英]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.javaIntent添加一个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.

相关问题 单击时如何触发微调器事件? - How can I trigger spinner event when on click? 每次更改设备方向后,如何防止小部件重新更新? - How can I prevent my widget from re-updating every time the device's orientation is changed? ImageJ - 更改ImageStack中的帧时的触发事件 - ImageJ - Trigger event when frame in ImageStack is changed 当传感器事件发生变化时,如何多次增加变量? - How can I increment the variable more than one time when sensor event changed? GWT:如何仅在按钮位于面板中时触发按钮单击事件? - GWT: How can I only trigger the button click event when the button is in a panel? 如何使用Intent打开用户的个人资料联系人? - How can I open the user's profile contact using an Intent? 如何使用Geckodriver保留Firefox配置文件的缓存? - How can I retain my Firefox profile's cache with Geckodriver? 当工作流的任务更改某些属性时,如何制定触发策略? - How can I make a policy that trigger when a workflow's task change some property? 如何打印触发事件的按钮名称? - How can i print the button name that trigger the event? 如何使用Robot类在组件上触发click事件? - How can I trigger a click event on a Component using the Robot class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM