Re: [android-developers] Re: Running a song after every one hour..
forgot to mention how I am calling my service in main activity class. Here is how I call the service: .. setContentView(R.layout.activity_main); MyService ms=new MyService(); ms.startService(new Intent(this,MyService.class).setAction("com.example.action.PLAY")); ... On Wednesday, May 1, 2013 1:49:11 PM UTC+5:30, Ravi Tewari wrote: > > Hi Piran/Bob, > I meant, I just needed a start and thanks to both of you to guide in a > right direction. > I have started developing it. At first, I am creating a Service to run the > music. > But need your help to clarify why it is not running for me (when I run it > using activity alone, it plays the song). > > Here is my main activity java file: > > public class MainActivity extends Activity { > protected void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.activity_main); > } > public boolean onCreateOptionsMenu(Menu menu) { > getMenuInflater().inflate(R.menu.main, menu); > return true; > } > } > > > And below is another class MyService.java which essentially is a service: > > public class MyService extends Service implements OnPreparedListener { > private static final String ACTION_PLAY = "com.example.action.PLAY"; > MediaPlayer mMediaPlayer = null; > Uri myUri=Uri.parse(getPackageResourcePath() + R.raw.shanti); > public int onStartCommand(Intent intent, int flags, int startId) { > if(intent.getAction().equals(ACTION_PLAY)){ >try { > mMediaPlayer=new MediaPlayer(); > mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); > mMediaPlayer.setDataSource(getApplicationContext(), myUri); > mMediaPlayer.setOnPreparedListener(this); > mMediaPlayer.prepareAsync(); >}catch(IOException e){ > mMediaPlayer=null; >} > } > return 0; > } > public void onPrepared(MediaPlayer mMediaPlayer) { > mMediaPlayer.start(); > } > public IBinder onBind(Intent intent) { > return null; > } > } > > In the Manifest file, I have included the service just by placing this > code: > > > When I am running it, nothing is happening !! > Can you please advise whats going wrong here? > Appreciate your reply. > > Peaceful Time Ahead... > > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [android-developers] Re: Running a song after every one hour..
Hi Piran/Bob, I meant, I just needed a start and thanks to both of you to guide in a right direction. I have started developing it. At first, I am creating a Service to run the music. But need your help to clarify why it is not running for me (when I run it using activity alone, it plays the song). Here is my main activity java file: public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } } And below is another class MyService.java which essentially is a service: public class MyService extends Service implements OnPreparedListener { private static final String ACTION_PLAY = "com.example.action.PLAY"; MediaPlayer mMediaPlayer = null; Uri myUri=Uri.parse(getPackageResourcePath() + R.raw.shanti); public int onStartCommand(Intent intent, int flags, int startId) { if(intent.getAction().equals(ACTION_PLAY)){ try { mMediaPlayer=new MediaPlayer(); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setDataSource(getApplicationContext(), myUri); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.prepareAsync(); }catch(IOException e){ mMediaPlayer=null; } } return 0; } public void onPrepared(MediaPlayer mMediaPlayer) { mMediaPlayer.start(); } public IBinder onBind(Intent intent) { return null; } } In the Manifest file, I have included the service just by placing this code: When I am running it, nothing is happening !! Can you please advise whats going wrong here? Appreciate your reply. Peaceful Time Ahead... -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [android-developers] Re: Running a song after every one hour..
seriously? so by "I need to create an app" and "can you help/guide me" you actually meant "can someone do the work for me?" On Tuesday, April 30, 2013 5:58:19 PM UTC+3, Ravi Tewari wrote: > > Thanks Piren.. Will look at it... But I was looking if someone already has > done similar > > > On Tue, Apr 30, 2013 at 8:23 PM, Piren >wrote: > >> http://developer.android.com/guide/topics/media/mediaplayer.html >> >> http://developer.android.com/reference/android/content/Intent.html#ACTION_BOOT_COMPLETED >> http://developer.android.com/reference/android/app/AlarmManager.html >> >> Figure it out :) >> >> >> On Tuesday, April 30, 2013 5:40:59 PM UTC+3, Ravi Tewari wrote: >>> >>> >>> I need to create an app that will play a song after every one hour. The >>> app will be running all the times but in background. As soon as it is 9 >>> o'clock, it will play a song. Once song is over, app should go idle. Again >>> as soon as it is 10 o'clock, it will again play that song. So on for >>> 365*24*7... Even after boot up the device, the app should get started >>> automatically. >>> >>> So is this possible, if yes, can you help/guide me in this? >>> Appreciate your response ! >>> >>> Peaceful time ahead... >>> >>> >>> >> -- >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to >> android-d...@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Android Developers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to android-developers+unsubscr...@googlegroups.com . >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [android-developers] Re: Running a song after every one hour..
Maybe this will help? *// Get a reference to the Alarm Manager * *AlarmManager alarmManager = (AlarmManager) getSystemService( Context.ALARM_SERVICE); * *// Set the alarm to wake the device if sleeping. * *int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP; * * * *// Schedule the alarm to repeat every half hour. * * * *long timeOrLengthofWait = AlarmManager.INTERVAL_HALF_HOUR; * * * *// Create a Pending Intent that will broadcast and action * *String ALARM_ACTION = "ALARM_ACTION"; * *Intent intentToFire = new Intent( ALARM_ACTION); * *PendingIntent alarmIntent = PendingIntent.getBroadcast( this, 0, intentToFire, 0); * * * *// Wake up the device to fire an alarm in half an hour, and every * *// half-hour after that. * * * *alarmManager.setInexactRepeating( alarmType, timeOrLengthofWait, timeOrLengthofWait, alarmIntent);* *Meier, Reto (2012-04-05). Professional Android 4 Application Development (Wrox Professional Guides) (Kindle Locations 9250-9257). John Wiley and Sons. Kindle Edition. * On Tuesday, April 30, 2013 9:58:19 AM UTC-5, Ravi Tewari wrote: > > Thanks Piren.. Will look at it... But I was looking if someone already has > done similar > > > On Tue, Apr 30, 2013 at 8:23 PM, Piren >wrote: > >> http://developer.android.com/guide/topics/media/mediaplayer.html >> >> http://developer.android.com/reference/android/content/Intent.html#ACTION_BOOT_COMPLETED >> http://developer.android.com/reference/android/app/AlarmManager.html >> >> Figure it out :) >> >> >> On Tuesday, April 30, 2013 5:40:59 PM UTC+3, Ravi Tewari wrote: >>> >>> >>> I need to create an app that will play a song after every one hour. The >>> app will be running all the times but in background. As soon as it is 9 >>> o'clock, it will play a song. Once song is over, app should go idle. Again >>> as soon as it is 10 o'clock, it will again play that song. So on for >>> 365*24*7... Even after boot up the device, the app should get started >>> automatically. >>> >>> So is this possible, if yes, can you help/guide me in this? >>> Appreciate your response ! >>> >>> Peaceful time ahead... >>> >>> >>> >> -- >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to >> android-d...@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> --- >> You received this message because you are subscribed to the Google Groups >> "Android Developers" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to android-developers+unsubscr...@googlegroups.com . >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [android-developers] Re: Running a song after every one hour..
Thanks Piren.. Will look at it... But I was looking if someone already has done similar On Tue, Apr 30, 2013 at 8:23 PM, Piren wrote: > http://developer.android.com/guide/topics/media/mediaplayer.html > > http://developer.android.com/reference/android/content/Intent.html#ACTION_BOOT_COMPLETED > http://developer.android.com/reference/android/app/AlarmManager.html > > Figure it out :) > > > On Tuesday, April 30, 2013 5:40:59 PM UTC+3, Ravi Tewari wrote: >> >> >> I need to create an app that will play a song after every one hour. The >> app will be running all the times but in background. As soon as it is 9 >> o'clock, it will play a song. Once song is over, app should go idle. Again >> as soon as it is 10 o'clock, it will again play that song. So on for >> 365*24*7... Even after boot up the device, the app should get started >> automatically. >> >> So is this possible, if yes, can you help/guide me in this? >> Appreciate your response ! >> >> Peaceful time ahead... >> >> >> > -- > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Android Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to android-developers+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: Running a song after every one hour..
http://developer.android.com/guide/topics/media/mediaplayer.html http://developer.android.com/reference/android/content/Intent.html#ACTION_BOOT_COMPLETED http://developer.android.com/reference/android/app/AlarmManager.html Figure it out :) On Tuesday, April 30, 2013 5:40:59 PM UTC+3, Ravi Tewari wrote: > > > I need to create an app that will play a song after every one hour. The > app will be running all the times but in background. As soon as it is 9 > o'clock, it will play a song. Once song is over, app should go idle. Again > as soon as it is 10 o'clock, it will again play that song. So on for > 365*24*7... Even after boot up the device, the app should get started > automatically. > > So is this possible, if yes, can you help/guide me in this? > Appreciate your response ! > > Peaceful time ahead... > > > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.