Boot complete in ICS - android

I am having a broadcast receiver that starts a service in ICS. I have not activity associated with the code. The issue that I am facing is that I am unable to receive the BOOT COMPLETED broadcast in my receiver. Is there a round about solution for this. To receive a boot complete intent in ICS. I read that
http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html
but what is the soultion. Can anyone help in this.

enter code here
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar">
<receiver
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
android:name=".BootComp"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
<service android:name="CheckForUpdateService"></service>
<activity android:name="Upgrade_choice"></activity>
</application>
This is my manifest file

This is my method in the receiver to receive the boot completed. I am starting a service on boot complete of the system.
if(("android.intent.action.BOOT_COMPLETED").equals(intent.getAction()))
{
Log.d(tag,"Received the BOOT COMPLETE intent");
Intent i=new Intent();
i.setAction("com.example.bootcompletecheck.CheckForUpdateService");
ctx.startService(i);
}
else
{
Log.d(tag,"----Not received----");
}
}
}

Related

receive sms broadcast after clear ram

i know this question may be asked by another user ...but i can not solve my problem
i create one broadcast for receive sms and it worked well but when user clear ram broadcast does not work ...
how i can create a broadcast that work even user clear ram
it is my code
public class ReceiveSms extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.i("log","sms received");
// Toast.makeText(App.context,"you have sms",Toast.LENGTH_SHORT).show();
Object[] pdus= (Object[]) intent.getExtras().get("pdus");
SmsMessage sms=SmsMessage.createFromPdu((byte[]) pdus[0]);
String body=sms.getMessageBody();
String sender=sms.getDisplayOriginatingAddress();
Log.i("log","sms body"+body);
Toast.makeText(App.context,"message from :"+sender,Toast.LENGTH_SHORT).show();
Intent startProgram=new Intent(App.context,MainActivity.class);
startProgram.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
App.context.startActivity(startProgram);
}
}
and mainfast
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.masiha68.sms">
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".RC"
android:process=":remote"
android:enabled="true"
>
</service>
<receiver android:name=".ReceiveSms"
android:process=":remote"
>
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED">
</action>
</intent-filter>
</receiver>
</application>
</manifest>
In huawei device, you need to enable you app in 'Protected apps' to keep running after the screen off or after you kill app from background.
For that goto,
Phone Manager -> Power saving -> Protected apps -> find your app and 'enable' it.

Launch Intent from and to a WallpaperService

I have a live wallpaper which displays an image. I change that image in an activity. I then need to notify the live wallpaper, so it knows to reload the resources.
Intents seemed like the perfect, simple, solution:
Intent intent = new Intent(MyActivity.this, MyWallpaperService.class);
startService(intent);
I and in MyWallpaperService
#Override
public int onStartCommand (Intent intent, int flags, int startId) {...}
I also need to know, in another service, when the user taps the screen. I use the exact same mechanism of sending and receiving the intent.
Everything is working perfectly on Android 4.0+ devices and emulators.
But I tested on Android 2.2 and 2.3.3 emulator and get the following error:
java.lang.SecurityException: Not allowed to start service Intent { cmp=com.domain.name/.liveWallpaper.MyWallpaperService } without permission android.permission.BIND_WALLPAPER
My manifest contains the correct android:permission inside the service tag:
<service
android:name=".liveWallpaper.MyWallpaperService"
android:label="#string/app_name"
android:permission="android.permission.BIND_WALLPAPER" >
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/livewallpaper_data" />
</service>
Why do I get this error only on old versions(Android 2.2 and 2.3.3)? Is sending Intents to a WallpaperService not allowed or recommended? Does it have something to do with the fact that only the system can bind to a service with the BIND_WALLPAPER permission?
In the end, if intents do not work, what is an alternative, simple, solution?
try to add the permission to your Service in the manifest file , like the following :
<service android:name=".LiveWallpaper"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:permission="android.permission.BIND_WALLPAPER">
Hope that Helps
java.lang.SecurityException: Not allowed to start service Intent {
cmp=com.domain.name/.liveWallpaper.MyWallpaperService } without
permission android.permission.BIND_WALLPAPER
means you probably forgot to declare the BIND_WALLPAPER permission within your AndroidManifest.xml like this:
<service
android:enabled="true"
android:name="MyWallpaperService"
android:permission="android.permission.BIND_WALLPAPER" />
Android Livewallpaper settings fail to load from 'configure...' menu
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.RrD"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-feature android:name="android.software.live_wallpaper" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BIND_WALLPAPER" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
>
<service android:name=".LiveWallpaper"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper"
android:resource="#xml/livewallpaper" />
</service>
<activity android:label="PAM_Prefs"
android:name=".PAM_Prefs"
android:exported="true" android:icon="#drawable/icon">
<intent-filter>
<category android:name="android.intent.category.PREFERENCE" />
</intent-filter>
</activity>
</application>
</manifest>
I still haven't found a exact explanation for why this isn't working, but I found a solution:
Creating a BroadcastReceiver that will receive my custom Intents. This means I will no longer be using startService(intent), but sendBroadcast(intent), which will not cause permission issues.
See the references for more explanations and code.
References:
https://groups.google.com/forum/#!topic/android-developers/N8TzbbKwd5o
Permission to BIND_WALLPAPER required when messaging WallpaperService from Settings Activity

android send action_call from broadcastreceiver

i want to forward all phone calls after receive a sms , so i have to using broadcastreceiver to listen incoming sms , this is my code :
public class SMSListiner extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED")) {
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + Uri.encode("*21*02164371348#")));
callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callIntent);
}}
and this is manifest
`
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arash.SMSListiner">
<uses-sdk android:minSdkVersion="10"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<action android:name="android.intent.category.LAUNCHER"></action>
</intent-filter>
</activity>
<receiver android:name=".SMSListiner">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.BROADCAST_SMS"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
</manifest>
`
call is sent but i have an error :
"call forwarding , connection problem or invalid MMI Code"
but when i try this code to send action_call in activity i have no problem and it work correctly ,
any idea ?

My Broadcast Receiver does not start

I have some problem with BroadcastReceiver. There nothing happens when I catch an outgoing call.
public class demoBroadcastReceiver extends BroadcastReceiver {
/** Called when the activity is first created. */
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "there is new calling", Toast.LENGTH_LONG).show();
}
}
This is content of my Manifest:
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name=".demoBroadcastReceiver">
<intent-filter >
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
<intent-filter >
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
Updated:
Thanks Lucifer for solution:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
I also need this:
<uses-permission android:name="android.permission.NEW_OUTGOING_CALL" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />**strong text**
You should declare this permission in your AndroidManifest.xml file
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
maybe you should post your log here, so we can analyse it.
try add this permission:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
Hope this
put this in your manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
and this in your application node..
<receiver android:name="com.example.demoBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <--- add this intent filter
</intent-filter>
</receiver>
this is to start a service when a device boots up on android

Broadcast receivers on reboot?

I need to write data in to a file ,when system reboots not on boot complete.
i am using broadcast receiver "android.intent.action.REBOOT" Below is my code and manifest files
public class broadcastreceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Log.i("LOG_TAG","rebooted");
}
manifest file:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".broadcast"
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="com.example.broadcastreceiver.broadcastreceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.REBOOT">
<intent-filter>
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
</receiver>
</application>
but i am not able to write even a log when reboots.
note:i donot want to use Bootcompleted action in broadcast receiver
I can't see why you don't want to use BootCompleted, could you provide your reasons?
There is no other action that will alert your broadcast receiver of the boot. You will have to use BootCompleted.
As a note, I hope you are registering you BroadcastReceiver with the context (since you didn't include that code). If you're not using BootComplete, I don't know what action you've registered to expect your above code to execute.
Add this, to me work, but on new devices, there are no testing.
For example in the recent nexus not working.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Categories

Resources