我想在用户更改手机的配置文件时触发一个事件,但我不确定如何触发。理想情况下,我可以捕获广播 Intent 并知道配置文件何时更改,但我无法找到任何相关文档。
如果我是对的,配置文件系统不是库存 AOSP 的一部分,而是 Cyanogenmod 的一部分。
我已经艰难地浏览了我能找到的仅有的两个与个人资料相关的类:
- https://github.com/CyanogenMod/android_frameworks_base/blob/cm-10.1/core/java/android/app/ProfileManager.java
- https://github.com/CyanogenMod/android_frameworks_base/blob/cm-10.1/core/java/android/app/Profile.java
我能找到的唯一广播 Intent 是 here 。
知道如何实现这一点吗?我的应用程序仅针对运行 Cyanogenmod 10.1 的设备。这是 CyanogenMod 的配置文件管理器,可以让您更清楚地了解我正在谈论的内容。
最佳答案
不确定我对你想要的是否正确,但就我而言,它效果很好。尝试一下它是否可以帮助你。
我在这里使用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();
}
});
}
显然这也可以帮助你..
关于java - 当设备的配置文件更改时,如何触发事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17361874/