English 中文(简体)
1. 在锁定国歌时确定比值
原标题:Setting Vibrate while in a lock state Android

I ve hit an interesting part in my studies with Android. I m as I go through I have created a timed PendingIntent to go off. Before it goes off, I lock the phone. When it goes off. I see it runs though and attempts to change the vibrate setting on my phone. Unfortunately it doesn t apply the setting.

code:

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "VibrateTag");
wakeLock.acquire();

AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

int ringerMode = audio.getRingerMode();
if(ringerMode != AudioManager.RINGER_MODE_NORMAL && item.getVibrate() && item.getVolume() != 0)
{
    audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}

final String INFO = "INFO";

int vibrateSetting = AudioManager.VIBRATE_SETTING_OFF;
if (item.getVolume() != 0)
{
    if (item.getVibrate()) vibrateSetting = AudioManager.VIBRATE_SETTING_ON;
}
else
{
    if (item.getVibrate()) vibrateSetting = AudioManager.VIBRATE_SETTING_ONLY_SILENT;
}

Log.e(INFO,"AReceiver attempting to update vibrate to " + vibrateSetting);

audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, vibrateSetting);

Log.e(INFO,"AReceiver updated vibrate to " + audio.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER));

wakeLock.release();

log when locked:

06-27 18:31:00.184: ERROR/INFO(3031): AReceiver attempting to update vibrate to 1
06-27 18:31:00.184: ERROR/INFO(3031): AReceiver updated vibrate to 0

Like I said when unlocked and in use, that log would read showing the change was successful where it would change its value to 1.

Now if I have my phone unlocked and I do this, it works. The Broadcast works (started on BootUp).

I ve even tried to lock down permissions to use with:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<uses-permission android:name="android.permission.VIBRATE"/>

<uses-permission android:name="android.permission.WAKE_LOCK"/>

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>

Now with that in mind, I also tried doing these things with and without the wake lock.

  1. 当处于锁定状态时,环境会发生变化?

  2. 我为何没有这样做? 我只想看一看一看一看。

Thanks, Kelly

最佳回答

目前,这些电话是用于工作的Im。 我认为,起作用的是修改电话。 希望这能够帮助其他人摆脱困境。

BTW. It really a pain some of the description in the google docs for this. Does anyone know of a better place that (I know this is a funny question because they re google s docs) describes the phone s user permissions.

One other thing. After some reading, it has been noted that the modify phone state has changed some with future behavior. Basically some hidden / undocumented classes / Interfaces can be used like in 2.2.

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<uses-permission android:name="android.permission.VIBRATE"/>

<uses-permission android:name="android.permission.WAKE_LOCK"/>

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签