0

i m setting vibrate mode in my app so that when notification comes phone gets vibrated. I do see many apps uses different profiles like low, medium & high as option in vibrate mode.

i know the way to use vibrate in android apps ie

Vibrator vibrator;
vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(3000);

for different profiles, we need to set the time manually or any system defined standard way is there to use for vibrate option?

Naruto
  • 9,476
  • 37
  • 118
  • 201
  • See this answer: http://stackoverflow.com/a/17066803/2649012 – Phantômaxx Jan 02 '15 at 18:30
  • Thank you for the link, actually i do play media when notification comes. If the phone is in silent mode, i need to trigger vibrator. So in this case i just need to check if the phone is in silent mode & then just trigget vibrator thats all right? – Naruto Jan 02 '15 at 18:36
  • Yes, you can. I'd also skip the silent check and let it vibrate always (with sound too). Or set it via Preferences (Enable Vibration?). – Phantômaxx Jan 02 '15 at 18:42
  • If the user has made the phone mute means, it should just vibrate right? what about silent? just leave it like that? – Naruto Jan 02 '15 at 18:48
  • Isn't `MUTE` a synonim of `SILENT`? Check this answer, too: http://stackoverflow.com/a/11985560/2649012. – Phantômaxx Jan 02 '15 at 18:54
  • you rock buddy, let me test that. also one last help, if you know pls tell me. i.e in list preference i have values & its stored as numbers i.e like ` Off Default Short Long 0 1 2 3 ` what is the best way to read them ? – Naruto Jan 02 '15 at 18:56
  • NOOOOOOOOOOOO!!! Please, son't use numbers as resource names! Jokes apart, try something like this: http://www.edumobile.org/android/android-development/listpreference-example/ – Phantômaxx Jan 02 '15 at 19:05
  • Oh, thank you for enlightening me. really i was not aware of this. i found this in one sample example. i'm checking your link. Also here they have provided the way to read list values from preferences right? – Naruto Jan 02 '15 at 19:14
  • Of course. Check this line: `String prefList = sharedPreferences.getString("PREF_LIST", "no selection");` – Phantômaxx Jan 02 '15 at 19:18
  • Ok, i got it. Suppose if my values format is like ` Off Default Short Long 0 1 2 3 ` Then above code gives me 1,2,3 values but not the text like low, medium or high right?. again we need to write some more code to get the strings based on 1,2,3 correct? – Naruto Jan 02 '15 at 19:25
  • The value stored in the preferences is a **single** key:value pair. Normally you give the key name as a string (say "listChoice") and get the result **value** as stored when saving the preference. Another sample (maybe cleaner, with images and a downloadable project): http://viralpatel.net/blogs/android-preferences-activity-example/ – Phantômaxx Jan 02 '15 at 19:32
  • But that guy has given array entries like ` Once a day Once a week Once a year Never (Update maually) 1 7 30 0 `. you said its not correct way? – Naruto Jan 02 '15 at 19:36
  • Ok, i got it now. depending on our requirement we need to create the array right. i understood now. its tricky. Thank you dude.. thanks lot – Naruto Jan 02 '15 at 19:38
  • Well, you actually **can**. But it's **not a preferred** way. It's much better to give proper names to resources. I don't give names to the items of an array. – Phantômaxx Jan 02 '15 at 19:41
  • ok, yes actually, see sometimes we may have to update the intensity like vibrate low, medium or high in preferences section for user. So there when user taps on list item we get number like 1,2,3 in this case we need to map the number and show thats the only option right. But when notification comes we get the direct vales from preferences and easily we can perform action like vibrate for 1 sec, 2 or 3. – Naruto Jan 02 '15 at 19:49
  • Like `value * 1000` (in ms). – Phantômaxx Jan 02 '15 at 19:59
  • Yes, this works well in notification time. But we need to show the type of vibrate in listpreference summary i.e low, medium or high in preferences for user. there we need to add some extra code to know what is 1, 2 or 3. – Naruto Jan 02 '15 at 20:02
  • You could get it from the string array resource: `getResources.getStringArray(R.array.listDescriptions)[value];` ... But there's a better approach: http://stackoverflow.com/a/24772748/2649012 – Phantômaxx Jan 02 '15 at 20:05
  • Closing now, it's late, must have dinner. – Phantômaxx Jan 02 '15 at 20:12
  • Wow, its good idea and straight fwd too.. thanks lot for the tip. thank you. was trying like `CharSequence[] entries = vibrateProfile.getEntries();` your technique is much easier – Naruto Jan 02 '15 at 20:13
  • 1
    Hey, thanks lot dude. thank you for your time & support. may god bless you. take care. lets meet some other time. thanks lot – Naruto Jan 02 '15 at 20:13
  • Hi Der, how are you?. Sorry for troubling you again. i need to use numberpicker in my preference fragment. After investigation i got to know that its possible from API 11 onwards, any custom one you prefer or alternatives for tat? – Naruto Jan 05 '15 at 16:05
  • Fine. And you? See this: http://developer.android.com/guide/topics/ui/settings.html#Custom – Phantômaxx Jan 05 '15 at 16:31
  • Thanks, i'm well. http://developer.android.com/images/ui/settings/settings.png. Yes i know this link, but i need some sample working example on how to implement. any hint or help from your side. i have provided image link – Naruto Jan 05 '15 at 16:40
  • I thought it was straihgt enough... So, maybe this one helps you more: http://www.i-programmer.info/programming/android/6418-android-adventures-pickers.html – Phantômaxx Jan 05 '15 at 17:09
  • Is it, ill have look. thanks... if i have doubt i'll ask you. – Naruto Jan 05 '15 at 17:27
  • HI, http://www.i-programmer.info/programming/android/6418-android-adventures-pickers.html?start=2 here they have told about numberpicker, But the numberpicker is present in API 11 onwards, i'm developing app from api level 8. so any best alternative numberpicker you know?? – Naruto Jan 05 '15 at 18:45
  • Any idea on this, https://github.com/SimonVT/android-numberpicker i imported this, it looks well. any idea? – Naruto Jan 05 '15 at 18:49
  • You are using the `support-library v4`, right? – Phantômaxx Jan 05 '15 at 18:51
  • This you are talking about doesn't seem to be anyhow related to `Preferences`. Just a NumberPicker. I thought we were talking of Preferences. – Phantômaxx Jan 05 '15 at 18:53
  • NO, i need to use numberpicker in my preference screen. i want to provide 1 to 60 number limit. user needs to set the number as the duration for reminder. like i need reminder after 30 mins, or 40 mins like that. i want numberpicker to launch on taping a preference item. – Naruto Jan 06 '15 at 17:52
  • any help on my above query? @DerGolem, thanks for your support – Naruto Jan 07 '15 at 04:47
  • You should have enough stuff to work on... – Phantômaxx Jan 07 '15 at 08:05
  • Hmm, i just want to launch number picker from preferences. The default numberpicker works well on API 11 onwards, i'm supporting for devices from API 8. Any hint/samples of how to launch it from preferences. if you know pls tell, – Naruto Jan 07 '15 at 10:56
  • 1
    Thanks for your continued support dude :) – Naruto Jan 07 '15 at 11:01
  • For more pickers, see this post: http://stackoverflow.com/questions/4216082/how-to-use-datepickerdialog-as-a-preference and http://stackoverflow.com/questions/5533078/timepicker-in-preferencescreen – Phantômaxx Jan 07 '15 at 11:16
  • Hi, u there, i need a small help in preferences again, hope u wont mind in helping, thanks in advance – Naruto Jan 15 '15 at 16:38
  • Ask, I'll see - I'm slow motion now, 'coz I'm following a tutorial on 3D modeling using displacement maps in Blender.. – Phantômaxx Jan 15 '15 at 16:42
  • Oh, ok well. thanks for your reply dude. Hey i'm using the SIMON VT lib i.e android.support.v4.preference.PreferenceFragment lib for my preference screen. The default ringtonepreference was not working for Android 4.0.4, hence i handle the `setOnPreferenceClickListener` and added code like below comment, (read next comment). Now the issue is with 4.1.2 device its launching 2 ringtone pickers one is the default one and custom one which is calling via intent, but for 4.0.4 device its working well. Now what to do?. i'm adding the code in next comment. – Naruto Jan 15 '15 at 16:47
  • ringtonepref.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); String path = settings.getString("prefnotificationTone", "content://settings/system/notification_sound"); Uri uri = !TextUtils.isEmpty(path) ? Uri.parse(path) : null; Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); – Naruto Jan 15 '15 at 16:50
  • ` intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); getActivity().startActivityForResult(intent, 1000); return true; } }); }` – Naruto Jan 15 '15 at 16:51
  • sorry the above code was too lengthy, i had to split it up. however ill format the code for better reading.. pls help me thanks – Naruto Jan 15 '15 at 16:52
  • This commentary is growing way too much... Consider posting a new question, instead. – Phantômaxx Jan 15 '15 at 16:56
  • can you come for chat at http://chat.stackoverflow.com/rooms/68900/naruto-issues. i think you can solve my issue pls – Naruto Jan 15 '15 at 17:11

0 Answers0