Re: [android-developers] How to show notification while service is running..?

2010-10-01 Thread Prakash Iyer
You should look at the appropriately named NotificationManager...

On Thu, Sep 30, 2010 at 1:00 PM, Gold thangadura...@gmail.com wrote:

 Hi,

I want to show notification in service..!

While I click button in my home screen I just call
 service.!

That service run every 30 seconds with the help of
 timer..! I want to show result to user..!

How can I implement this..! Herewith I attached
 code..


 HOme screen
 --

 package com.servicetest;

 import java.util.Timer;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.Toast;

 public class Home extends Activity
 {
private Button btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button)findViewById(R.id.Button01);

btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
 Hai,
 Toast.LENGTH_SHORT).show();
Intent in = new Intent();
in.setClassName(com.servicetest,
 com.servicetest.ServiceTest);
startService(in);
}
});
}
 }


 ServiceTest.java
 ---


 package com.servicetest;

 import java.util.Date;
 import java.util.Timer;
 import java.util.TimerTask;

 import android.app.AlertDialog;
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.Service;
 import android.content.Intent;
 import android.media.MediaPlayer;
 import android.os.IBinder;
 import android.util.Log;
 import android.widget.Toast;

 public class ServiceTest extends Service
 {
private Timer timer = new Timer();
private static final String TAG = MyService;
MediaPlayer player;
WebserviceConnect wsConnect = new WebserviceConnect();
String result = ;
boolean flag = true;
private long delay = 1000;
public static final int NOTIFICATION_ID_RECEIVED = 01221;

@Override
public IBinder onBind(Intent intent)
{
return null;
}

@Override
public void onCreate()
{
Toast.makeText(this, My Service Created,
 Toast.LENGTH_LONG).show();
Log.d(TAG, onCreate);
}

@Override
public void onDestroy()
{
Toast.makeText(this, My Service Stopped,
 Toast.LENGTH_LONG).show();
Log.d(TAG, onDestroy);
}

@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, My Service Started,
 Toast.LENGTH_LONG).show();
Log.d(TAG, onStart);

timer.scheduleAtFixedRate(new TimerTask()
{

@Override
public void run()
{
// TODO Auto-generated method stub
result = wsConnect.Connect(CheckStatus,
 ID, 7x897);
Log.d(TAG,result);
}

}, delay  , delay);

Log.d(TAG,result);
Toast.makeText(getApplicationContext(), result, 5).show();
if (result.equals(Success))
{
timer.cancel();
timer = null;
}
}

 }




 Thanks  Warm Regards,
 Gold

 --
 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.comandroid-developers%2bunsubscr...@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 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

Re: [android-developers] How to show notification while service is running..?

2010-10-01 Thread Miguel Morales
What exactly isn't working?  Not really a question.  The service runs
in the same thread as your app so you should be ok.
Part of being a good programmer is asking good questions and properly
reading documentation.

On Fri, Oct 1, 2010 at 2:41 PM, Prakash Iyer thei...@gmail.com wrote:
 You should look at the appropriately named NotificationManager...

 On Thu, Sep 30, 2010 at 1:00 PM, Gold thangadura...@gmail.com wrote:

 Hi,

                    I want to show notification in service..!

                    While I click button in my home screen I just call
 service.!

                    That service run every 30 seconds with the help of
 timer..! I want to show result to user..!

                    How can I implement this..! Herewith I attached
 code..


 HOme screen
 --

 package com.servicetest;

 import java.util.Timer;

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.Toast;

 public class Home extends Activity
 {
        private Button btn;
    /** Called when the activity is first created. */
   �...@override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn = (Button)findViewById(R.id.Button01);

        btn.setOnClickListener(new OnClickListener() {

                       �...@override
                        public void onClick(View v)
                        {
                                // TODO Auto-generated method stub
                                Toast.makeText(getApplicationContext(),
 Hai,
 Toast.LENGTH_SHORT).show();
                                Intent in = new Intent();
                                in.setClassName(com.servicetest,
 com.servicetest.ServiceTest);
                                startService(in);
                        }
                });
    }
 }


 ServiceTest.java
 ---


 package com.servicetest;

 import java.util.Date;
 import java.util.Timer;
 import java.util.TimerTask;

 import android.app.AlertDialog;
 import android.app.Notification;
 import android.app.NotificationManager;
 import android.app.Service;
 import android.content.Intent;
 import android.media.MediaPlayer;
 import android.os.IBinder;
 import android.util.Log;
 import android.widget.Toast;

 public class ServiceTest extends Service
 {
        private Timer timer = new Timer();
        private static final String TAG = MyService;
        MediaPlayer player;
        WebserviceConnect wsConnect = new WebserviceConnect();
        String result = ;
        boolean flag = true;
        private long delay = 1000;
        public static final int NOTIFICATION_ID_RECEIVED = 01221;

       �...@override
        public IBinder onBind(Intent intent)
        {
                return null;
        }

       �...@override
        public void onCreate()
        {
                Toast.makeText(this, My Service Created,
 Toast.LENGTH_LONG).show();
                Log.d(TAG, onCreate);
        }

       �...@override
        public void onDestroy()
        {
                Toast.makeText(this, My Service Stopped,
 Toast.LENGTH_LONG).show();
                Log.d(TAG, onDestroy);
        }

       �...@override
        public void onStart(Intent intent, int startid) {
                Toast.makeText(this, My Service Started,
 Toast.LENGTH_LONG).show();
                Log.d(TAG, onStart);

                timer.scheduleAtFixedRate(new TimerTask()
                {

                       �...@override
                        public void run()
                        {
                                // TODO Auto-generated method stub
                                result = wsConnect.Connect(CheckStatus,
 ID, 7x897);
                                Log.d(TAG,result);
                        }

                }, delay  , delay);

                Log.d(TAG,result);
                Toast.makeText(getApplicationContext(), result, 5).show();
                if (result.equals(Success))
                {
                        timer.cancel();
                        timer = null;
                }
        }

 }




 Thanks  Warm Regards,
 Gold

 --
 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 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 

Re: [android-developers] How to show notification while service is running..?

2010-09-30 Thread TreKing
On Thu, Sep 30, 2010 at 12:00 PM, Gold thangadura...@gmail.com wrote:

 I want to show notification in service..!


OK..! http://developer.android.com/reference/android/app/Service.html

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
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