Creating a BackGround application

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Postby joemarshalmathew » Mon Feb 01, 2010 4:45 pm

I tried with the code that u provided thanks a lot :D

now i have one more problem i tried to implement PhoneStateListener for analyzing the Phone state from the OnBootReceiver

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package im.maillard.android.onbootservice;
  2.  
  3.  
  4. import android.content.BroadcastReceiver;
  5. import android.content.ComponentName;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.telephony.PhoneStateListener;
  9. import android.telephony.TelephonyManager;
  10. import android.util.Log;
  11.  
  12. public class OnBootReceiver extends BroadcastReceiver {
  13.  
  14.         public static final String TAG = "TestApp";
  15.  
  16.         @Override
  17.         public void onReceive(Context context, Intent intent) {
  18.                 Log.d("TestApp", "Got the Boot Event>>>");
  19.                 Log.d("TestApp", "Starting MySimpleService>>>");
  20.                 context.startService(new Intent().setComponent(new ComponentName(
  21.                                 context.getPackageName(), MySimpleService.class.getName())));
  22.  
  23.                 TelephonyManager telephony = (TelephonyManager) context
  24.                                 .getSystemService(Context.TELEPHONY_SERVICE);
  25.                 MyPhoneStateListener myPhoneStateListener = new MyPhoneStateListener ();
  26.                 Log.d("TestApp", "Starting Listeneing Call State");
  27.                 telephony.listen(myPhoneStateListener ,
  28.                                 PhoneStateListener.LISTEN_CALL_STATE);
  29.                 Log.d("TestApp", "Started Listeneing Call State");
  30.  
  31.         }
  32. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package im.maillard.android.onbootservice;
  2.  
  3. import android.telephony.PhoneStateListener;
  4. import android.telephony.TelephonyManager;
  5. import android.util.Log;
  6.  
  7. public class MyPhoneStateListener extends PhoneStateListener {
  8.        
  9.         @Override
  10.         public void onCallStateChanged(int state, String incomingNumber) {
  11.                 switch (state) {
  12.                 case TelephonyManager.CALL_STATE_IDLE:
  13.                         Log.d("DEBUG", "IDLE");
  14.                         break;
  15.                 case TelephonyManager.CALL_STATE_OFFHOOK:
  16.                         Log.d("DEBUG", "OFFHOOK");
  17.                         break;
  18.                 case TelephonyManager.CALL_STATE_RINGING:
  19.                         Log.d("DEBUG", "RINGING");
  20.                         break;
  21.                 }
  22.         }
  23. }
  24.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


i got this log
Starting Listeneing Call State

after that
UnsupportedOperationException
on executing
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. telephony.listen(myPhoneStateListener,
  2.                                 PhoneStateListener.LISTEN_CALL_STATE);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


I had added
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <uses-permission android:name="android.permission.READ_PHONE_STATE" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
in the manifest file

i dont know why i got this exception on executing the statement

can u advice me on this

And once again Thanks for the help :)
joemarshalmathew
Freshman
Freshman
 
Posts: 9
Joined: Sun Jan 03, 2010 6:25 am
Location: Kochi,India

Top

Postby xma » Mon Feb 01, 2010 9:21 pm

Sorry I posted wrong AndroidManifest.xml, the uses-permission should be after/before the <application></application> block:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.         package="im.maillard.android.onbootservice" android:versionCode="1"
  4.         android:versionName="1.0">
  5.         <application android:icon="@drawable/icon" android:label="@string/app_name">
  6.                 <receiver android:name=".OnBootReceiver" android:enabled="true"
  7.                         android:exported="false" android:label="OnBootReceiver">
  8.                         <intent-filter>
  9.                                 <action android:name="android.intent.action.BOOT_COMPLETED" />
  10.                         </intent-filter>
  11.                 </receiver>
  12.        
  13.                 <service android:name="MySimpleService" android:enabled="true"
  14.                         android:exported="false" android:label="MySimpleService" />
  15.         </application>
  16.         <uses-sdk android:minSdkVersion="4" />
  17.                 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  18.                 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  19. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


It should be ok after that small modification (at least it works here):

I/ActivityManager( 52): Start proc im.maillard.android.onbootservice for broadcast im.maillard.android.onbootservice/.OnBootReceiver: pid=187 uid=10023 gids={}
I/jdwp ( 187): received file descriptor 20 from ADB
D/ddm-heap( 187): Got feature list request
I/ActivityManager( 52): Stopping service: com.android.providers.downloads/.DownloadService
D/TestApp ( 187): Got the Boot Event>>>
D/TestApp ( 187): Starting MySimpleService>>>
D/TestApp ( 187): Starting Listeneing Call State>>>
D/TestApp ( 187): <<<Started Listeneing Call State
D/TestApp ( 187): >>>onCreate()
D/TestApp ( 187): >>>onStart()
D/DEBUG ( 187): IDLE
xma
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Sep 03, 2009 10:10 pm

Mesaging Intent

Postby dhaiwat » Tue Feb 02, 2010 5:39 am

hi

i want to start my activity from service when user touch on Messaging application of android.
can u tell me which Intent is call on receive so that i put in AndroidManifest.xm file to start my application on touch of Messaging of android.

Dhaiwat Bhavsar
dhaiwat
Developer
Developer
 
Posts: 28
Joined: Tue Feb 10, 2009 6:49 am

Postby xma » Tue Feb 02, 2010 12:57 pm

Sorry but I do not understand your request. Can you be more explicit please ?
xma
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Sep 03, 2009 10:10 pm

messaging intent

Postby dhaiwat » Tue Feb 02, 2010 1:22 pm

Hi

I want to start My own application when user click or touch the inbuilt messaging logo/Application of android
it is possible if yes than how.

My effort till now:

Start service on boot. as u describe.
now how this service know that user click/touch(com.android.mms) Intent and i start my activity from here.


Dhaiwat Bhavsar(dhaiwat.bhavsar@yahoo.com)
dhaiwat
Developer
Developer
 
Posts: 28
Joined: Tue Feb 10, 2009 6:49 am

Postby xma » Tue Feb 02, 2010 9:02 pm

I do not see why you need a ON_BOOT receiver for that task but anyway.

You need to define an intent-filter stanza like this (in your AndroidManifest file):

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.    <intent-filter>
  2.  
  3.                  <action android:name="android.intent.action.VIEW" />
  4.  
  5.                  <action android:name="android.intent.action.EDIT" />
  6.  
  7.                  <action android:name="android.intent.action.PICK" />
  8.  
  9.                  <category android:name="android.intent.category.DEFAULT" />
  10.  
  11.                  <data android:mimeType="vnd.android-dir/mms-sms" />
  12.  
  13.     </intent-filter>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Then your activity will appear whenever someone wants to interact with MMS/SMS.

As far as I know you can't intercept basic messaging application launch and hook on it.
xma
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Sep 03, 2009 10:10 pm

Top

Query again

Postby dhaiwat » Wed Feb 03, 2010 9:32 am

hi

can u describe me how exactly i start my activity.

Dhaiwat Bhavsar
dhaiwat
Developer
Developer
 
Posts: 28
Joined: Tue Feb 10, 2009 6:49 am

Postby xma » Wed Feb 03, 2010 1:12 pm

Maybe you should read http://developer.android.com/intl/fr/index.html before trying to do anything. I have the feeling you did not read anything but just want recipes to do things without the basic knowledge.

SOrry I can't paraphrase all the docs ;)
xma
Junior Developer
Junior Developer
 
Posts: 16
Joined: Thu Sep 03, 2009 10:10 pm

Top
Previous

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests