Is there a way how to start and android application after a boot automatically if it is on the /sdcard?
Ok, probably by BroadcastReceiver. But which action is the right one?
ACTION_BOOT_COMPLETED - does not work if it is on the /sdcard (documented)
ACTION_MEDIA_MOUNTED - does not work if it is on the /sdcard (which is undocumented)
ACTION_EXTERNAL_APPLICATIONS_AVAILABLE - does not work, I do not know why
ACTION_USER_PRESENT - does not work if the BroadcastReceiver is registered in AndroidManifest (which is undocumented, but documentation bug has been reported)
Thanks
Jan
try using <receiver android:name=".BootCompleteReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
and this <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
perhaps QUICKBOOT_POWERON help u
Please mention it in manifest file.
</uses-permission>
<receiver android:name=".BootReceiver"
android:enabled="true"
android:exported="true"
android:label="BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
provide permission "android.permission.RECEIVE_BOOT_COMPLETED" as child of menifest.
and one more thing your app must not be installed in sdcard.
According to Google, you should not put any app you want to run at boot on an external drive.
"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."
http://developer.android.com/guide/topics/data/install-location.html#ShouldNot
I usually register every intent filter for a broadcast receiver both ways (Android Manifest as well as dynamically in a class that extends Application)
In AndroidManifest.xml as:
<receiver
android:name=".broadcastReciever"
android:enabled="true"
android:exported="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE" />
</intent-filter>
</receiver>
and in a class that extends Application:
registerReceiver(new broadcastReciever(), new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE));
and don't forget to add RECEIVE_BOOT_COMPLETED permission and register the class which extends Application in the Android Manifest.
This should do; feel free to ask for any more help/clarification.
Related
I recently did a code scan on my Android source code using HPFortify service. They reported security vulnerability regarding google analytics receiver. They suggested to use the broadcaster permission to reduce the attack vector. This way you are restricting broadcaster, otherwise any malicious application can send the intent and broadcast receiver will process it.
Here is my AndroidManifest file.
<receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
I am trying to figure out the broadcaster permission for AnalyticsReceiver. According to HpFortify the broadcast receiver should look like similar to this:
<receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:permission="SOME-GOOGLE-ANALYTICS-PERMISSION"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
</intent-filter>
</receiver>
Edit 1:
I am also looking for the source code to figure out the right permission. But I couldn't find the google analytics source code.
I am working on an app which will be pre-installed in the android device and i want to trigger it in background when end user actually start using its smart phone from the very first time. So is there any broadcast fired for this purpose or any other possible way to do this?
I've used a BroadcastReceiver to accomplish the running something on start, and as for knowing if it's the first time, you could use a shared preference for the app to track it's status of first time or not with a boolean.
Define a BroadcastReceiver the receiver will need the following in the manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver
android:name="com.androidfactorem.airwaves.BootAirWaveService"
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>
You can see a full implementation of a BroadcastReceiver on boot in my git project https://github.com/pbirdsall/airwave
I have a broadcastReceiver registered in manifest that receives broadcasts sent from one of my services with a custom action. I have it already working but for security reasons i want to prevent other apps from sending fake broadcast to my receiver. How can i do that?
Manifest
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="MyAction"/>
</intent-filter>
</receiver>
Every reciever with exported tag set to false will only receive broadcasts sent from its own application process.
so it will be:
<receiver android:name=".MyReceiver"
android:exported="false">
<intent-filter>
<action android:name="MyAction"/>
</intent-filter>
</receiver>
As another solution i found that i can use permissions.
more on here
I am making an android app, in which the app must launch just before the phone is shutting down. Is that possible?
Here i am not talking about encountering phone shutdown event when my app is running.
You will need this permission in your manifest file
<uses-permission android:name="android.permission.DEVICE_POWER" />
And you will listen to the intent like this
<receiver android:name=".ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
You can look at the links here for some description and here for official documentation.
I don't know the exact application where you want to use it, but you can have a background service running with the receiver for this intent.
I am new to android. I am using a Broadcast receiver which listens when a app is installed or removed.. When a app is installed or removed my Broadcast Receivers's onReceive(context,intent) will be called.. Now i need to get the info about the application installed or removed (Mainly the package name)..
Plz help
You can try this receiver and permission. (But this seem only work in /system/app)^^"
<receiver
android:name="com.your.receiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />
All the information you want is in the Intent extras.
Look at How to find the package name which has been uninstalled when using Intent.ACTION_PACKAGE_REMOVED