IntentReceiver only application

Tutorials with advanced 'difficulty' and more Lines of Code.

IntentReceiver only application

Postby dtmilano » Fri Feb 29, 2008 12:13 pm

It's possible to have an application consisting only of an IntentReceiver and no Activity.
See the details in this blog post.
I've found this through trial an error, so I hope this helps save you some time.

:idea: AndroidManifest.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5.    package="com.codtech.android.training.sampleintentreceiver">
  6.  
  7.     <application android:icon="@drawable/icon">
  8.  
  9.         <receiver android:name=".SampleIntentReceiver">
  10.  
  11.                 <intent-filter>
  12.  
  13.                         <action android:name="com.codtech.android.training.intent.SAMPLE_ACTION"/>
  14.  
  15.                 </intent-filter>
  16.  
  17.                 <intent-filter>
  18.  
  19.                         <action android:name="android.intent.action.GET_CONTENT"/>
  20.  
  21.                         <data android:mimeType="image/*"/>
  22.  
  23.                         <category android:name="android.intent.category.DEFAULT"/>
  24.  
  25.                 </intent-filter>
  26.  
  27.         </receiver>
  28.  
  29.     </application>
  30.  
  31. </manifest>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

:idea: Sample Intenteceiver:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. /**
  2.  
  3.  * Copyright © 2008 Diego Torres Milano <dtmilano at gmail dot com>
  4.  
  5.  */
  6.  
  7. package com.codtech.android.training.intentreceiver;
  8.  
  9.  
  10.  
  11. import android.content.Context;
  12.  
  13. import android.content.Intent;
  14.  
  15. import android.content.IntentReceiver;
  16.  
  17. import android.util.Log;
  18.  
  19. import android.widget.Toast;
  20.  
  21.  
  22.  
  23. /**
  24.  
  25.  * @author diego
  26.  
  27.  *
  28.  
  29.  */
  30.  
  31. public class SampleIntentReceiver extends IntentReceiver {
  32.  
  33.         private static final String TAG = "SampleIntentReceiver";
  34.  
  35.  
  36.  
  37.         /*
  38.  
  39.          * (non-Javadoc)
  40.  
  41.          *
  42.  
  43.          * @see android.content.IntentReceiver#onReceiveIntent(android.content.Context,
  44.  
  45.          *      android.content.Intent)
  46.  
  47.          */
  48.  
  49.         @Override
  50.  
  51.         public void onReceiveIntent(Context context, Intent intent) {
  52.  
  53.                 String msg = "SampleIntentReceiver:nonReceiveIntent(context="
  54.  
  55.                                 + context.getPackageName()
  56.  
  57.                                 + ", intent=[" + intent.getAction() + ", " + intent.getType()
  58.  
  59.                                 + ", " + intent.getData() + "])";
  60.  
  61.                 Log.d(TAG, msg);
  62.  
  63.                 Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
  64.  
  65.         }
  66.  
  67. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
dtmilano
Freshman
Freshman
 
Posts: 6
Joined: Thu Jan 24, 2008 9:40 am

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests