Launch Activity on System/Emulator Startup

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby sbfalbo » Sun Feb 17, 2008 5:13 pm

Does anyone know if the BOOT_COMPLETED action is still valid in the new Android SDK build (m5 rc14)? I had the startup receiver working fine in the previous SDK build but now it seems to not be working. Thanks!
sbfalbo
Freshman
Freshman
 
Posts: 8
Joined: Wed Dec 26, 2007 7:17 pm

Top

Postby sbfalbo » Fri Feb 22, 2008 1:41 pm

You need to add android.permission.RECEIVE_BOOT_COMPLETED to your AndroidManifest.xml as of SDK version m5-rc14.
sbfalbo
Freshman
Freshman
 
Posts: 8
Joined: Wed Dec 26, 2007 7:17 pm

Postby Delirio » Mon Mar 03, 2008 12:16 pm

Hi,


It still doesn't work with RECEIVE_BOOT_COMPLETED permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
I just get a "Permission Denial" warming message in the log:
WARN/ActivityManager(513): Permission Denial: receiving Intent { action=android.intent.action.BOOT_COMPLETED } from android requires android.permission.RECEIVE_BOOT_COMPLETED

how could I fix it?

Thanks in advance
Delirio
Freshman
Freshman
 
Posts: 6
Joined: Mon Mar 03, 2008 12:08 pm

Postby plusminus » Mon Mar 03, 2008 1:41 pm

Hello Delirio,

please post your AndroidManifest.xml

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Delirio » Mon Mar 03, 2008 5:49 pm

Here you are:

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="my.test">
  6.  
  7.         <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />    
  8.  
  9.         <application android:icon="@drawable/icon" android:name="MainApplication">    
  10.  
  11.              <activity android:name=".ActTest" android:label="@string/app_name">
  12.  
  13.                     <intent-filter>
  14.  
  15.                         <action android:name="android.intent.action.MAIN" />
  16.  
  17.                         <category android:name="android.intent.category.LAUNCHER" />
  18.  
  19.                     </intent-filter>
  20.  
  21.             </activity>
  22.  
  23.             <receiver android:name="ReceiverTest">
  24.  
  25.                         <intent-filter>
  26.  
  27.                                 <action android:name="android.intent.action.BOOT_COMPLETED"/>
  28.  
  29.                                 <category android:name="android.intent.category.HOME" />                                       
  30.  
  31.                         </intent-filter>
  32.  
  33.                 </receiver>
  34.  
  35.                 <activity android:name="OtherActivity" android:clearOnBackground="false"/>
  36.  
  37.         </application>
  38.  
  39. </manifest>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Delirio
Freshman
Freshman
 
Posts: 6
Joined: Mon Mar 03, 2008 12:08 pm

Postby plusminus » Mon Mar 03, 2008 7:06 pm

Hello delirio,

check whether this is your error:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <receiver android:name=".ReceiverTest">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

insead of:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <receiver android:name="ReceiverTest">
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Also check if the receiver is placed in the package "my.test".

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby Delirio » Tue Mar 04, 2008 2:09 pm

Ok thanks,

I was just paying attention to the Logcat messages

The log keeps showing the Permission Denial warning but the IntentReceiver gets the BOOT_COMPLETED intent, so finally it works
Delirio
Freshman
Freshman
 
Posts: 6
Joined: Mon Mar 03, 2008 12:08 pm

Postby plusminus » Tue Mar 04, 2008 2:36 pm

Hello Delirio,

maybe you need to reset the emulator once with -wipe-data to make the warning also disappear.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Delirio » Tue Mar 04, 2008 3:34 pm

Hi plusminus,

nop, the warning persists but the code works

thanks very much anyway
Delirio
Freshman
Freshman
 
Posts: 6
Joined: Mon Mar 03, 2008 12:08 pm

Start a service??

Postby xayide » Tue Mar 25, 2008 5:16 pm

Hello!

I find this tutorial very interesting. I want to do something similar, but instead of launching an activity, i want to launch a service.

I try to do that this way:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class TheService extends IntentReceiver {
  2.  
  3.  
  4.  
  5.     @Override
  6.  
  7.     public void onReceiveIntent(Context context, Intent intent) {    
  8.  
  9.          
  10.  
  11.                   Intent i = new Intent();
  12.  
  13.                   i.setClass(context, MyPosition.class);
  14.  
  15.                   Bundle b = new Bundle();
  16.  
  17.                   startService(i,b);
  18.  
  19.          
  20.  
  21.     }
  22.  
  23. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


But the problem is that i can´t do startService(i,b) from an intentReceiver.

Is there anyway to launch a service from an intentReceiver?

thanks!!
xayide
Junior Developer
Junior Developer
 
Posts: 20
Joined: Tue Feb 05, 2008 1:23 pm

Postby Delirio » Tue Mar 25, 2008 5:35 pm

Hi xayide,

Just use the context instance given in the method parameter:

context.startService(ib,b);
Delirio
Freshman
Freshman
 
Posts: 6
Joined: Mon Mar 03, 2008 12:08 pm

Postby xayide » Tue Mar 25, 2008 6:03 pm

I did that, but it doesn´t work at all!!

This is my manifest:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />  
  3.  
  4.         <service android:name=".anotherService" >
  5.  
  6.             <intent-filter>
  7.  
  8.                 <action android:name="android.intent.action.MAIN" />
  9.  
  10.                 <category android:name="android.intent.category.LAUNCHER" />
  11.  
  12.             </intent-filter>
  13.  
  14.         </service>
  15.  
  16.         <receiver android:name=".TheService">
  17.  
  18.             <intent-filter>
  19.  
  20.                  <action android:name="android.intent.action.BOOT_COMPLETED" />
  21.  
  22.                  <category android:name="android.intent.category.HOME" />
  23.  
  24.             </intent-filter>
  25.  
  26.         </receiver>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


the intent receiver

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class TheService extends IntentReceiver {
  2.  
  3.  
  4.  
  5.     @Override
  6.  
  7.     public void onReceiveIntent(Context context, Intent intent) {
  8.  
  9.         Log.d("iam in TheService","");
  10.  
  11.          /* Create intent which will finally start the Main-Activity. */
  12.  
  13.          Intent myStarterIntent = new Intent(context,anotherService.class);
  14.  
  15.          /* Set the Launch-Flag to the Intent. */
  16.  
  17.          myStarterIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
  18.  
  19.          /* Send the Intent to the OS. */
  20.  
  21.          Bundle b=new Bundle();
  22.  
  23.          //context.startService(myStarterIntent, );
  24.  
  25.          context.startService(myStarterIntent, b);               
  26.  
  27.     }
  28.  
  29. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


it doesn´t print the log.d text
xayide
Junior Developer
Junior Developer
 
Posts: 20
Joined: Tue Feb 05, 2008 1:23 pm

Postby Delirio » Wed Mar 26, 2008 1:04 pm

Maybe the error is that the tag uses-permission is inside the application tag in your android manifest , it should be placed this way (or at least I think so):

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  3.  
  4. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.package">
  5.  
  6. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  7.  
  8.     <application android:icon="@drawable/icon" android:label="Application" android:name="Application">
  9.  
  10.         <receiver android:name=".anotherService" >
  11.  
  12.             <intent-filter>
  13.  
  14.                  <action  android:name="android.intent.action.BOOT_COMPLETED"  />
  15.  
  16.                  <category android:name="android.intent.category.HOME" />
  17.  
  18.             </intent-filter>
  19.  
  20.         </receiver>                  
  21.  
  22.     <service android:name="TheService" />
  23.  
  24. </application>
  25.  
  26. </manifest>
  27.  
  28.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
Delirio
Freshman
Freshman
 
Posts: 6
Joined: Mon Mar 03, 2008 12:08 pm

Postby xayide » Wed Mar 26, 2008 8:17 pm

Hi!

It´s necessary to add all this permissions, otherwise it doesn´t work. It seems that with the new sdk release it is necessary to add all of them.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_CELL_ID" />

However, it just work if i close the emulator and launch a new one. It doesn´t work if i relaunch just the application. I don´t know if it should do like this...

I have a question: do you have problems with the emulator? i launch it and sometimes it doesn´t appear in the ddms perspective, other times it gives me errors saying that the emulator is not found... Other times it gives errors such as, home is not responding, my application is not responding...

regards!
xayide
Junior Developer
Junior Developer
 
Posts: 20
Joined: Tue Feb 05, 2008 1:23 pm

android.intent.action.BOOT_COMPLETED

Postby stilwalli » Tue Jul 29, 2008 10:00 am

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.HelloWorld">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="@drawable/icon">
<activity android:name=".HelloWorld" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".Start" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
</application>
</manifest>

package com.HelloWorld;

import android.content.Context;
import android.content.Intent;
import android.content.IntentReceiver;
import android.os.Bundle;
import android.util.Log;

public class Start extends IntentReceiver {

public void onReceiveIntent(Context context, Intent intent) {
if (intent.getAction().toString().equals("android.intent.action.BOOT_COMPLETED")) {
Log.i("Test", "121212");
Intent myStarterIntent = new Intent(context,HelloWorld.class);
/* Set the Launch-Flag to the Intent. */
myStarterIntent.setLaunchFlags(Intent.NEW_TASK_LAUNCH);
/* Send the Intent to the OS. */
Bundle b=new Bundle();
//context.startService(myStarterIntent, );
context.startService(myStarterIntent, b);
}
}

}

//HelloWorld is an activity that displays hello world.

I keep getting this error
WARN/PackageManager(510): Granting new permission android.permission.RECEIVE_BOOT_COMPLETED to android.server.PackageManagerService$SharedUserSetting@400c04d0
WARN/ActivityManager(510): Permission Denial: receiving Intent { action=android.intent.action.BOOT_COMPLETED } from android requires android.permission.RECEIVE_BOOT_COMPLETED


Please help
stilwalli
Developer
Developer
 
Posts: 35
Joined: Mon Jul 21, 2008 8:13 am

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests