How to get sound notification?

by Jenie » Sat, 27 Sep 2008 01:41:59 GMT


Sponsored Links
 In this code i don't get any sound for notification...Help me..
/***
        Copyright (c) 2008 CommonsWare, LLC

        Licensed under the Apache License, Version 2.0 (the "License"); you
may
        not use this file except in compliance with the License. You may
obtain
        a copy of the License at
                 http://www.apache.org/licenses/LICENSE-2.0 
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
        See the License for the specific language governing permissions and
        limitations under the License.
*/

package com.commonsware.android.notify;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Timer;
import java.util.TimerTask;

public class NotifyDemo extends Activity
{
        private static final int NOTIFY_ME_ID=1337;
        private Timer timer=new Timer();

        @Override
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                Button btn=(Button)findViewById(R.id.notify);

                btn.setOnClickListener(new View.OnClickListener()
                {
                        public void onClick(View view)
                        {
                                setDefault(Notification.DEFAULT_SOUND);
                                TimerTask task=new TimerTask()
                                {
                                        public void run()
                                        {
                                                notifyMe();
                                        }
                                };
                                timer.schedule(task, 5000);
                        }
                });

                btn=(Button)findViewById(R.id.cancel);

                btn.setOnClickListener(new View.OnClickListener()
                {
                        public void onClick(View view)
                        {
                                NotificationManager
mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

                                mgr.cancel(NOTIFY_ME_ID);
                        }
                });
        }

        protected void setDefault(int defaultSound) {
                // TODO Auto-generated method stub

        }

        private void notifyMe()
        {
                final NotificationManager
mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
                Notification note=new Notification(R.drawable.red_ball,"Status
message!",System.currentTimeMillis());
                PendingIntent i=PendingIntent.getActivity(this, 0,new 
Intent(this,
NotifyMessage.class),0);

                note.setLatestEventInfo(this, "Notification Title","This is the
notification message", i);


                mgr.notify(NOTIFY_ME_ID, note);
        }
}

--~--~---------~--~----~------------~-------~--~----~



How to get sound notification?

by Mark Murphy » Sat, 27 Sep 2008 02:04:02 GMT


 > In this code i don't get any sound for notification...Help me..

Hey! This code looks familiar!


There is no sound associated with this Notification. You would probably
need to set the sound and audioStreamType public data members of the
Notification object to have it make a sound.

One of the ApiDemos probably demonstrates this, though the machine I'm
typing this on does not have the 1.0 SDK, so I can't cite any specifically
at this time.

--
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.2 Published!



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. TabWidget Error

In Eclipse when i try to midify the main form if i use a TabWdget
control i get the following error: NullPointerException: null

and in the console window i have this:
"java.lang.NullPointerException
        at android.widget.TabWidget.dispatchDraw(TabWidget.java:105)
        at android.view.ViewGroup.drawChild(ViewGroup.java:1434)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1208)
        at android.view.ViewGroup.drawChild(ViewGroup.java:1434)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1208)
        at android.view.View.draw(View.java:5465)
        at android.widget.FrameLayout.draw(FrameLayout.java:324)
        at com.android.layoutlib.bridge.Bridge.computeLayout(Bridge.java:338)
        at
com.android.ide.eclipse.adt.internal.editors.layout.GraphicalLayoutEditor.computeLayout
(Unknown Source)
        at
com.android.ide.eclipse.adt.internal.editors.layout.GraphicalLayoutEditor.recomputeLayout
(Unknown Source)
        at
com.android.ide.eclipse.adt.internal.editors.layout.GraphicalLayoutEditor.activated
(Unknown Source)
        at
com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.pageChange
(Unknown Source)
        at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected
(MultiPageEditorPart.java:291)
        at org.eclipse.swt.widgets.TypedListener.handleEvent
(TypedListener.java:228)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
        at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:770)
        at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:
3256)
        at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:2045)
        at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:
323)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:
3880)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3473)
        at com.android.sdkuilib.internal.repository.UpdaterWindowImpl.open
(UpdaterWindowImpl.java:104)
        at com.android.sdkuilib.repository.UpdaterWindow.open
(UpdaterWindow.java:110)
        at
com.android.ide.eclipse.adt.internal.wizards.actions.AvdManagerAction.run
(Unknown Source)
        at org.eclipse.ui.internal.PluginAction.runWithEvent
(PluginAction.java:251)
        at org.eclipse.ui.internal.WWinPluginAction.runWithEvent
(WWinPluginAction.java:229)
        at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection
(ActionContributionItem.java:584)
        at org.eclipse.jface.action.ActionContributionItem.access$2
(ActionContributionItem.java:501)
        at org.eclipse.jface.action.ActionContributionItem$6.handleEvent
(ActionContributionItem.java:452)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:
3880)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3473)
        at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:
2405)
        at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
        at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault
(Realm.java:332)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench
(Workbench.java:493)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:
149)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start
(IDEApplication.java:113)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run
(EclipseAppHandle.java:194)
        at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication
(EclipseAppLauncher.java:110)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start
(EclipseAppLauncher.java:79)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:368)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:179)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1311)"
Does anybody has any idea?
Thanks

-- 

2. ListActivity mandatory for listView ?

I am starting with ListActivity.

I saw apidemos and saw that it is based on ListActivity. My doubt is,
in my first screen I need a few labels and texts under that a list.
How to approach this ? I cant do a setContentlayut(R.id.main) if my
activity extends ListActivity, no ?

more over I found the tutorial posted in the forums for ListActivity a
bit outdated. Where is 1.5 / 1.6 based tutorials ? because I am new,
it is taking too much time to correct 1.1 codes.

lastly, if i have a todo type appfor adding deleting and deleting,
should i use 3 different layouts or activities ?

-- 

3. How to set same XML attributes to all activities

4. Integrate GMAIL within an Android app....

5. strategy to keep a scale after an animation

6. Emulator on Linux 10 times slower than on Windows

7. Emulator on Linux 10 times slower than on Windows