The following is the code I'm using for starting my Application when device is turned on.
public class BootReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Log.i("BootReceiver","intent received");
Intent myIntent = new Intent(context, ACT_Home.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
and in the Manifest (as <Application> child):
<receiver android:name="host.alarmmanager.BootReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
The permissions inside the Manifest are the following:
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
This works fine on Android 3.2.2, but if I try the same application on Android 4.0.3 the broadcast receiver does not receive anything.
Also the first line inside the onReceive method is not execeuted.
Why this happens?
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
This you should use in android manifest
Try this, although your code seems fine! The following is working for me.
<!-- Receivers -->
<receiver android:enabled="true" android:name="host.alarmmanager.BootReceiver"
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>
Make sure you are not restarting your phone by selecting restart option from the power menu.
Android bizarrely has 2 different permissions.
1.Reboot
2.On boot complete
So,
first power off your phone and then after few seconds power on it again!
Hope it helps! (Y)
Related
I have configured my app to automatically start on boot and it's working but only the first time :/
The manifest
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.SHUTDOWN"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<receiver android:name=".autostart" android:enabled="true" android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<action android:name="android.intent.action.REBOOT"/>
<!--For HTC devices-->
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
The autostart
public class autostart 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);
Log.d("AutoStart", "AutoStart");
}
}
I restart and shutdown the app with this code :
public static void Reboot(CaniGPSApplication caniGPSApplication) throws IOException, InterruptedException {
Process proc = Runtime.getRuntime().exec(new String[] { "/system/bin/svc", "power", "reboot" });
proc.waitFor();
}
public static void Shutdown(CaniGPSApplication caniGPSApplication) throws IOException, InterruptedException {
Process proc = Runtime.getRuntime().exec(new String[] { "/system/bin/svc", "power", "shutdown" });
proc.waitFor();
}
I have no idea why my apps doesn't start the second time. I am working on a GPS device (no screen ...) and my app is in system/priv-app .
Hope someone will have an idea :)
I have found a solution.
First I remove autostart block which is not more used
<receiver android:name=".autostart"
And I have added the HOME category in my main activity
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
From the documentation
This is the home activity, that is the first activity that is
displayed when the device boots.
Perfect for my case : a simple GPS device, but I think a bad idea on a phone :)
I have an application that correctly receives notifications, even when the application has been killed by swiping. However, after a longer period of inactivity (e.g. application not used for ~2 weeks) the notifications stop getting delivered. The behavior is consistent with applications that have been force stopped (http://developer.android.com/about/versions/android-3.1.html#launchcontrols). However, I am confident that the application has not been force stopped.
To elaborate, the device receives the GCM message and the intent is triggered, but the application is not available to process it. See log excerpt below for details on what happens when notification is sent.
03-30 19:43:24.596: I/GCM(4931): GCM message com.company.application 0:1459359805552536%60ff11d7f9fd7ecd
03-30 19:43:24.606: W/GCM-DMM(4931): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.company.application (has extras) }
Does android sometimes force idle applications into a stopped state? Is there reason for this to occur other than a stopped state?
If it matters, notifications are implemented using Urban Airship, but I had similiar problems before migrating from Parse.
Code excerpts below.
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.application"
android:versionCode="27"
android:versionName="1.31">
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.company.application.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.company.application.permission.C2D_MESSAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<application
android:name=".MyApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".Main"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
<activity android:name=".ParseDeepLinkActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<!-- Handles any vnd.company.application://deeplink URI's -->
<data android:scheme="vnd.company.application" android:host="deeplink" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
</application>
</manifest>
Application
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
UAirship.takeOff(this, new UAirship.OnReadyCallback() {
#Override
public void onAirshipReady(UAirship airship) {
// Enable user notifications
airship.getPushManager().setUserNotificationsEnabled(true);
}
});
}
}
Are you implementing a WakeLock object? Do you set a keepalive value for your GCM messages? I suggest you start by checking both points or post some more code / details so we can understand the whole scope :)
I am happily receiving notifications when app is in background and foreground but when app is killed, I am not receiving notifications in some phones (like Xiaomi model phones eg mi3, etc.)
GCM message 0:1434141725194227%03b66390f9fd7ecd
broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg= (has extras) }
Although I am getting notifications in other phones like nexus, samsung, others.
Did anyone also had similar problem?
Can someone explain me where I am wrong.
Here is my Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<package_name>">
<permission android:name="<package_name>.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="<package_name>.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
<action android:name="android.net.wifi.STATE_CHANGE"/>
<application
android:name="<package_name>.ApplicationSingleton"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="<package_name>.ui.activity.ReferralActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="<package_name>.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="<package_name>" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="<package_name>"/>
</intent-filter>
</receiver>
<service android:name="<package_name>.gcm.GcmIntentService" />
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Autostart probably the best MIUI feature that doesn’t come enabled by default, but should.
What does autostart do? It basically starts the apps you select when the phone starts, so you never miss any notifications or updates.
To enable autostart for your apps, follow the steps below:
Tap on the Security app from the app screen.
You will not find this if you enter from the Settings menu, you have to tap directly on the app icon.
Open Security App:
Once in the Security app, tap on Permissions.
Tap on Autostart
Toggle the apps you want to enable Autostart for
Reboot your phone.
Now you are all set up with autostart!
I am developing a SIP application for VOIP calls. I have modified SIPDemo as per my UI requirements. When an incoming call is triggered, my app is registered to server domain and able to receive calls, (even in the case when the app is not running).
But when my app is destroyed/killed, incoming calls are not triggered.
I have made service start, i think its not running. I'm new to this and unable to figure out, Kindly suggest the help!
Manifest Declaration:
For Service:
<service
android:name=".CallDetectService"
android:process=".com.example.mysip.callservice"
android:enabled="true"
android:exported="false" >
</service>
For Receiver:
<receiver
android:name=".receiver.ServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Manifest Permissions:
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature
android:name="android.hardware.sip.voip"
android:required="true" />
<uses-feature
android:name="android.hardware.wifi"
android:required="true" />
<uses-feature
android:name="android.hardware.microphone"
android:required="true" />
all your manifest declarations are good,,, and as for keeping your app running that depends on how well your service is made... here is an answer that I hope it helps you:
AlarmManager or Service
I'm trying to implement push notifications in my app, but it seems that my C2DMReceiver is not working. I tried every solution I could find. Here is what I have:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10" />
<permission android:name="com.my.app.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="com.my.app.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<activity>....</activity>
<service android:name=".C2DMReceiver"/>
<receiver
android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.my.app"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.my.app"/>
</intent-filter>
</receiver>
In my onCreate method I use:
C2DMessaging.register(this, "mymail#gmail.com");
String id = C2DMessaging.getRegistrationId(this);
And id is always empty.
Looking at the LogCat, I can see Permission Denial: receiving Intent { act=com.google.android.c2dm.intent.REGISTRATION So, what should I do?Thanks)
Change your android:name in your receiver tag from com.google.android.c2dm.C2DMBroadcastReceiver to com.my.app.YourReceiverClassName, and make sure your sender e-mail and server side login e-mail are the same.
The android:name in your receiver has to specify the path to your class that implements the receiver. I am sure that your C2DMBroadcastReceiver class is not in the com.google.android.c2dm package, as I see below your are using a com.my.app package.
Create a C2DMBroadcastReceiver class in, for example, com.my.app.receiver and specify the receiver's adroid:name as:
<receiver
android:name="com.my.app.receiver.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
......
</receiver>