- I am trying a simple example with broadcast receiver registered with action BOOT_COMPLETED... but, application is not giving toast message... I searched a lot.. tried both the ways of registering receiver in manifest.xml and in java code also... but I really don't know what is the problem in it...
- please help me to sort out this issue as i need to start service on boot up..
- thanks in advance..
1) Activity class
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
Toast.makeText(context, "Boot is completed..", Toast.LENGTH_SHORT).show();
}
}
2) manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bootupservicedemoagain"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="com.example.bootupservicedemoagain.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
</application>
</manifest>
I have also tried this in activity class onReceive
method but same outcome!
if(intent.getAction() != null)
{
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
Toast.makeText(context, "Boot is completed..", Toast.LENGTH_SHORT).show();
}
}
0 comments:
Post a Comment