Android: Boot Broadcast not working after Reboot - java

I have an app that uses a broadcast service to continue my pending intent after it reboots, but its not working as its supposed to. After I reboot my phone i get pop-up notification saying MyAppsName has stopped working. And the log I made for it does not appear.
manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.idkbro.pashchallenge">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<application
android:allowBackup="true"
android:name=".BaseApplication"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
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>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".AlertReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<receiver
android:name=".BootReceiver"
android:enabled="true"
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>
<service
android:name=".NotificationService"
android:exported="true"></service>
</application>
The BootReceiver:
#Override
public void onReceive(Context context, Intent intent) {
Log.i("Xu", "Boot receiver is working");
}

Just add this in receiver class:
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
Log.i("Xu", "Boot receiver is working");
}
And remove permission and category intent filter from manifest reciver tag like:
<receiver
android:name=".BootReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

Related

I have warning "App is not indexable by Google Search; consider adding at least one Activity with an ACTION-VIEW intent filter. "

After the update, the following warning appeared in the studio:
“App is not indexable by Google Search; consider adding ACTION-VIEW intent filter. See issue explanation for more details. more ... (Ctrl + F1) »
How to fix it?
My Api is 28.
Here is my manifests:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.omen.serverforcofe" >
<uses-permission android:name="android.permission.NFC"/>
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application
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"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain"
/>
</intent-filter>
</activity>
</application>
</manifest>
<activity
android:name=".MyActivity"
android:screenOrientation="portrait"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
Adding this intent filter to one of the activities declared in app manifest fixed this for me.

Android 6.0 Broadcast Receiver don't receive BOOT_COMPLETE

My receiver is not working with Android 6.0 Marshmallow.
I am sending a broadcast through adb shell, see below:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED received
if application was open, App say:Working!
But if the application was not open, it has not been returning anything.
My code is here;
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.berate.rebootreceiverfromb3r0">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" android:protectionLevel="signature|development"></uses-permission>
<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>
<receiver android:name="com.example.berate.rebootreceiverfromb3r0.Yakala_Receiver">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"></category>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
</application>
</manifest>
Receiver.Java;
public class Yakala_Receiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"i got it ",Toast.LENGTH_SHORT).show();
}
}
Edit: I have very interesting info, My code is working on samsung (Android 6.0) devices. But my (Android 6.0) devices not responding me
change this
<receiver android:name="com.example.berate.rebootreceiverfromb3r0.Yakala_Receiver">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"></category>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
to this
<receiver android:name="com.example.berate.rebootreceiverfromb3r0.Yakala_Receiver" android:enabled="true" android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"></category>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
hope it helps
I fixed, some new android devices have security application by default. some times these apps lock your auto-start mode.

Android - Java - Have app run when device boots up

I am having a bit of an issue here, my code seems right, but its not doing what I am expecting it too.
I have an app and I would like to run when the device boots up. But when the device boots up, it application does not run, which is what I am expecting.
First in my Manifest, I added the uses-permission for RECEIVE_BOOT_COMPLETED:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Then also in my Manifest I added a receiver and activity inside the application:
<application
android:allowBackup="true"
android:icon="#drawable/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=".BootReceiver"
android:enabled="true"
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>
<activity
android:name=".BootReceiver"
android:label="#string/title_activity_boot_receiver" >
</activity>
</application>
And then I created a BootReceiver Activity that looks like this:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
When I install the app, boot the device, the app does not run right when the device boots up.
I do not understand what I am doing wrong here. Is my code wrong? Anyone got any ideas?
BootReceiver is not your Activity it is class which extends broadcast receiver.
update your manifest, this will be enough
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<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=".BootReceiver"
android:enabled="true"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
/>
</intent-filter>
</receiver>
</application>
Step #1: Get rid of <activity android:name=".BootReceiver" ..., as you do not have an Activity named BootReceiver.
Step #2: Get rid of <category android:name="android.intent.category.DEFAULT" />, as categories are not usually used on broadcasts, and definitely is not used here.
Step #3: Get rid of android:permission="android.permission.RECEIVE_BOOT_COMPLETED", as that indicates that the sender of the broadcast must hold that permission, which may not be true.
You will be looking to have a manifest that looks more like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android.sysevents.boot"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="11"/>
<supports-screens
android:largeScreens="false"
android:normalScreens="true"
android:smallScreens="false"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity
android:name="BootstrapActivity"
android:theme="#android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
(from this sample app)
That's strange 'cause all you mentioned with Manifest and code seems good...
So do you mean no MainActivity is running after Boot?
BTW I used this in my Manifest and works fine:
<receiver
android:name="com.example.BootMeUp"
android:enabled="true"
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>
Try this: This code works for me....
<receiver
android:name="your.package.name.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

No launcher activity found!, yet I've specified one

When I specify the .main class as the launcher, it crashes on launch. So I made a new activity called launch that will be used to open the .main class. When I specify .launch as the LAUNCHER, the console tells me that no launcher activity was found.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.homework"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<application android:label="#string/app_name"
android:theme="#style/AppTheme"
android:allowBackup="true">
<activity android:name=".launch"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.LAUNCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".menu"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".list"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.LIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Change
<intent-filter>
<action android:name="android.intent.action.LAUNCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
to
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Well, does the com.my.homework.launch class exist? Does it subclass Activity? Also, the action should still be <action android:name="android.intent.action.MAIN" />.

Android-Installing to device using eclipse install two instance of same app at once-error

Android-Installing to device using eclipse install two instance of same app at once-error
and it runs when just after installed using the eclipse but when I touch the once of the icon its not starting it shows me the android common error syaing unexpectedly stopped!! please help me??
This is the manifest I'm using(activities)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hunter99x"
android:icon="#drawable/icon"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".main" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".origine" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.origine" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity `enter code here`android:name=".Gameover" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LandingScreen" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>
I think the issue is because you have repeated
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
this for 2 activities. Try removing this and declare just 1 acivity as your main. Tjis may solve your issue.
Try this code inside the activities and check if it works:
#Override
public void onBackPressed() {
finish();
System.exit(0);
}

Categories