I want to start the app on boot but wont get launched - android

Hi am trying to start the application on boot. App starts whenever boot completed but application launched and activity screen came to front. I want to start the app on boot but wont get launched. i included the manifest and BootUpReceiver.java .. Thanks.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.startapp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:enabled="true" android:name=".BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".StartApp"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<manifest>
BootUpReceiver.Java
public class BootUpReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent arg1) {
Intent i = new Intent(context, StartApp.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}

I think you would like to start a Service which runs in the background instead of an Activity.
There is a question regarding that issue here.

Could it be that you are testing this on a HTC and have "Fast boot" enabled (Settings -> Power -> Fast boot). In that case no BOOT_COMPLETED will be sent.
Some more information in my question Detect if HTC “Fast boot” is enabled

Related

Broadcastreceiver not working after boot

I have created an apps that will receive notifications from firebase thus hoping to start the app service after user boot their phone so that they do not need to manually start the apps again. However, the broadcast receiver seems to just not working.
AndroidManifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.simplifiedcoding.firebasecloudmessaging">
<!-- Adding Internet Permission -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
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>
<!--
Defining Services
-->
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".NotificationService"/>
<receiver android:name=".Broadcast" android:exported="true" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
</manifest>
Broadcast.java (BroadcastReceiver)
public class Broadcast extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent){
Intent service = new Intent(context, NotificationService.class);
context.startService(service);
Toast.makeText(context, "Broadcast started", Toast.LENGTH_LONG).show();
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I have checked the followings
Permission RECEIVE_BOOT_COMPLETED declared and not within tag
receiver tag is being written correctly
Am I doing wrong or still missing something else? Do I have to call it at mainAcitivity which I doubt I should ? Any guidance are much appreciated.
Got the solution and it was a very dumb reason.
I'm using Oppo's phone to test and Oppo has its own Security Manager App where you have to manually allow specific apps to be start up automatically after boot. That's all.
I suspect most android phones has this feature as well thus bear in mind to check whether there is such app and if it does then remind the user to allow the apps in the Security Manager App before they start rebooting their phone and not able to use any service's your App intended to provide.
Hope this helps!
Try this, it worked for me.
<receiver android:enabled="true" android:name=".Broadcast"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

My broadcast receiver can't get BOOT_COMPLETED broadcast

I install and open it , and reboot my phone , but my receiver did't receive broadcast to start my service and without log.
My phone is Asus LF2 .
How can I start my service in device boot completed?
My Receiver
public class BootReceiver extends BroadcastReceiver {
private final String TAG = getClass().getSimpleName();
public BootReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG , "Deyu onReceive " + intent.getAction());
context.startService(new Intent(context, AlarmMessageService.class));
}
}
My manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="go.deyu.dailytodo"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".app.App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
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=".receiver.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<service
android:name=".AlarmMessageService"
android:enabled="true">
</service>
</application>
</manifest>
I find why my app in my phone can't get boot complete broadcast.
There is a Auto-start Manager setting in my Asus Phone.
When I allow my app to Auto-start , my App work fine....
Remove android:permission="android.permission.RECEIVE_BOOT_COMPLETED" from the <receiver> element.
Try below code
<receiver
android:name=".receivers.RestartReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Android 3.1 or above,if you want to deal with android.intent.action.BOOT_COMPLETED broadcastreceiver.You must pay attention to this:
http://developer.android.com/about/versions/android-3.1.html#launchcontrols
1.Make sure you have turned on your app after you installed.I think you did it.
2.Check your android mobile device settings: Settings -> Apps -> Your App -> Force Stop.If the Force Stop is turned on,please turn off it.
3.Another point you should check is android:name=".receiver.BootReceiver",be careful of the path,maybe system can not find your BootReceiver.

Issue with automatically starting app

I see this has been asked quite a bit, but I can't seem to resolve my problem with what is out there.
My onReceive() method in broadcast receiver isn't being called.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.app.test.TestActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<receiver android:enabled="true" android:name=".BootUpReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
BootUpReceiver.java
package com.app.test;
public class BootUpReceiver extends BroadcastReceiver {
private static final String TAG = "TESTAPP_BootUpReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "helllllllllllllllo");
Toast.makeText(context, "boot completed received", Toast.LENGTH_LONG).show();
// Intent i = new Intent(context, TestActivity.class);
// i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(i);
}
}
Have tried using the entire path instead of .BootUpReceiver, didn't work. Not seeing anything from logcat or any Toast messages. Going into adb shell and emitting the boot_completed event that way doesn't help as the device then reboots.
Is there anything I am doing wrong? I read something about applications being inactive when device boots, does that affect my problem?
Here are some reference in Android developer website
http://developer.android.com/guide/topics/data/install-location.html
Broadcast Receivers listening for "boot completed"
The system delivers the ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast.

my application not start on BootUp mobile [duplicate]

This question already has answers here:
how to start my application when ever mobile restart or turn on
(3 answers)
Closed 9 years ago.
this is my manifiest file below my application not start my application when i turn On mobile i follow this like how to start my application when ever mobile restart or turn on
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.installedapps22"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="#drawable/cherry_icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
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:enabled="true" android:name="com.app.reciever.BootUpReciever">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name=".ListInstalledApps" > </activity>
<activity android:name=".TabsLayoutActivity" />
</application>
</manifest>
Class File
package com.example.installedapps22;
public class BootUpReciever extends BroadcastReceiver
{
#Override
public void onReceive(final Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
Check this question of mine, and the answer provided - they are related, and might solve your problem:
Intent.ACTION_USER_PRESENT not received on HoneyComb or ICS (Samsung) devices
Even though the intent used is different, the security issue I describe below is similar.
The problem might be that you need to run the application once BEFORE it will respond to the BOOT_COMPLETED intent.
This is a security measure.
If you do not run the application, it will not start on boot. Give it a try.
i.e.
write app
install app
RUN APP
reboot phone to check if it works

How do i attach debugger for bootup receiver in android?

I am new in android.I had started one service on bootup completed of device in my project but i am not having idea about how do i attach debugger for it.i.e i want to debug my code for some bugs so how should i proceed for that?please help me out.Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.broadcast.receiver.example"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true">
<activity android:name=".BR_Example"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Declaring broadcast receiver for wifi status changing event -->
<receiver android:name=".MyReceiver " android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
public MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent myIntent = new Intent(context, YourService.class);
context.startService(myIntent);
}
i hope it will help you man ............

Categories

Resources