Android Community
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: How to create a service?

  1. #1
    Join Date
    Sep 2008
    Posts
    683

    Default How to create a service?


    Anyone know? im not 100% clear on what Intents are for either and the documentation doesnt help me.

    Sprint HTC Evo 4G - Rooted
    CyanogenMod 6.0.0 Froyo 2.2 ROM
    CM6-Snap 7.6

    Check out my site Exodus Apps, we will be developing applications for the Notion Ink Adam Tablet soon!

    Follow us on Twitter @Exodusapps
    Follow me on Twitter @Aaron_Blank

  2. #2
    Join Date
    Sep 2008
    Location
    clemson south carolina
    Posts
    166

    Default Re: How to create a service?

    exactly wat do u mean service.. lik apps.. phone service can u be a little more detailed

  3. #3
    Join Date
    Sep 2008
    Posts
    47

    Default Re: How to create a service?

    i think he means he wants to create an app which runs as a service in the background, for example windows has a print spooler service.

    I did notice in the gravity Ringer application he has options for activating and deactivating the service so maybe some use to you if you can contact the programmer or get the source, link below.

    http://code.google.com/p/snowservice.../GravityRinger

  4. #4
    Join Date
    Sep 2008
    Location
    Berkeley, CA
    Posts
    73

  5. #5
    Join Date
    Sep 2008
    Location
    Berkeley, CA
    Posts
    73

  6. #6

    Cool Re: How to create a service?

    Hello Friends,
    Myself Prashant.

    Me giving u WebService Example for Android.

    Part - 1:
    In this part I giving small demo for webservice running in Android device.
    From this link you can find this example. Where I give Comment for webservice demo.
    Please all of you check it.
    http://lukencode.com/2010/04/27/call...t/#comment-179

    Part - 2: Webservice running in Android with database connectivity
    Now I am running database connectivity and return value from database and showing in Android device.
    Here i m using Microsoft SQL connectivity. You can use your way.
    For that u have to download this file
    SQL connectivity jar file for webservice:
    http://www.4shared.com/file/IxoPooiE/sqljdbc.html
    Ksoap Library File for android project.
    http://www.4shared.com/file/uOhx5aoj...ly-24-jar.html

    This is good example for you all.

    First We create Dynamic Project usign Eclipse
    Add this package and class.
    Package Name: org.webservice.pa
    Class Name : GetDatabaseRecords.java
    and also create once class for bean.(Setter-Getter Property).
    Class Name : BookData.java


    BookData.java

    package org.webservice.pa;

    public class BookData {
    public String bookCode;
    public String bookName;
    public String authorName;

    public String getBookCode() {
    return bookCode;
    }
    public void setBookCode(String bookCode) {
    this.bookCode = bookCode;
    }
    public String getBookName() {
    return bookName;
    }
    public void setBookName(String bookName) {
    this.bookName = bookName;
    }
    public String getAuthorName() {
    return authorName;
    }
    public void setAuthorName(String authorName) {
    this.authorName = authorName;
    }

    }


    GetDatabaseRecords.java

    package org.webservice.pa;
    public class GetDatabaseRecords{

    public BookData[] getBookDetails{
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    ArrayList<BookData> bookDataList = new ArrayList<BookData>();
    BookData bookData = null;
    try
    {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");//Driver Name
    con = DriverManager.getConnection("connectionUrl");//connection URL
    stmt = con.createStatement();
    rs = stmt.executeQuery("select * from BookDetails");//Table Name
    while (rs.next())
    {
    bookData= new BookData();
    bookData.setBookCode(rs.getString("bookCode"));
    bookData.setBookName(rs.getString("bookName"));
    bookData.setAuthorName(rs.getString("authorName")) ;
    bookDataList.add(bookData);
    }
    }catch (Exception e)
    {
    e.printStackTrace();
    }
    finally {
    try {
    rs.close();
    } catch(Exception e) {}
    try {
    stmn.close();
    } catch(Exception e) {}
    try {
    con.close();
    } catch(Exception e) {}
    }
    return (BookData[])bookDataList.toArray(new BookData[bookDataList.size()]);
    }
    }

    Now Right click on GetDatabaseRecords.java file and select "WebService" option.
    Now further step is same as posted my Part 1:
    Click finish.
    and test your service it will return BookData object.
    Here our Dynamic WebProject task is completed.


    Now you want to create Android Project for calling above WebService.
    Now u add "ksoap" library File in android project:
    Download from here:
    http://www.4shared.com/file/uOhx5aoj...ly-24-jar.html

    public class MainActivity extends Activity {
    private String METHOD_NAME = "getBookDetails"; // our webservice method name
    private String NAMESPACE = "http://pa.webservice.org"; // Here package name in webservice with reverse order.
    private String SOAP_ACTION = NAMESPACE + METHOD_NAME; // NAMESPACE + method name
    private static final String URL = "http://192.168.1.1:8080/WebServiceDemo/services/GetDatabaseRecords?wsdl"; // you must use ipaddress here, don't use Hostname or localhost

    public void onCreate(Bundle icicle)
    {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    TextView tv = (TextView) findViewById(R.id.txtsearch);
    try
    {
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.call(SOAP_ACTION,envelope);
    SoapObect so = (SoapObject)envelope.bodyIn;

    System.out.println("Counter: "+so.getPropertyCount());

    for(int i =0; i < so.getPropertyCount(); i++){
    SoapObject soap = (SoapObject) so.getProperty(i);
    System.out.println("BookCode :: "+ soap.getProperty("bookCode"));
    System.out.println("BookName :: "+ soap.getProperty("bookName"));
    System.out.println("AuthorName :: "+ soap.getProperty("authorName"));
    }

    tv.setText(so.toString());
    } catch (Exception E) {
    E.printStackTrace();
    tv.setText("ERROR:" + E.getClass().getName() + ": " + E.getMessage());
    }
    }
    }


    Now you can run your project and it's work fine


    And if you have any doubt just tell me.


    Thanks & Regards,
    Prashant Adesara.

  7. #7

    Default Re: How to create a service?

    Hi,

    I created the web service correctly and its working fine and then created an Android application also as said above but when i ran the android app on my emulator its says permission denied. I followed the link given in Part - 1.

    Can u please help me??

    Regards,
    Rohit
    Last edited by rohit.nagamalla; 09-20-2010 at 07:40 AM.

  8. #8
    Join Date
    Dec 2008
    Location
    Virginia
    Posts
    1,365

    Default Re: How to create a service?

    Quote Originally Posted by rohit.nagamalla View Post
    Hi,

    I created the web service correctly and its working fine and then created an Android application also as said above but when i ran the android app on my emulator its says permission denied. I followed the link given in Part - 1.

    Can u please help me??

    Regards,
    Rohit
    What does your AndroidManifest.xml look like?

  9. #9

    Default Re: How to create a service?

    Code:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="org.blx.com"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".MainActivity"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
        </application>
    </manifest>
    This is how my manifest file looks like....
    Last edited by rohit.nagamalla; 09-20-2010 at 08:33 AM.

  10. #10
    Join Date
    Dec 2008
    Location
    Virginia
    Posts
    1,365

    Default Re: How to create a service?


    Yeah... you need to define your service, similar to:

    Code:
     <service android:name=".myservice.MyService"/>
    Follow a tutorial like this one: http://developerlife.com/tutorials/?p=356

    You also need to add permission for your service to access the internet.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. How to create database using android API
    By sangram in forum Developers Guild
    Replies: 5
    Last Post: 03-15-2011, 10:06 PM
  2. Which service provider do you want to have the next Android?
    By refused9150 in forum General Phone Chat
    Replies: 16
    Last Post: 09-23-2008, 02:51 AM
  3. [ web service on android]
    By boufnichel in forum Developers Guild
    Replies: 0
    Last Post: 06-11-2008, 12:07 PM
  4. XMPP Service
    By Appugouda in forum Developers Guild
    Replies: 0
    Last Post: 04-02-2008, 11:57 PM
  5. How to create Ad-Hoc Mode access point
    By primal in forum Developers Guild
    Replies: 0
    Last Post: 03-01-2008, 04:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •