I have specified a receiver in the manifest like so ..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.MyProject"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher" android:enabled="true">
<service android:name="MyService"
android:exported="true"
android:process=":different"
android:enabled="true">
<intent-filter>
<action android:name="com.me.MyService">
</action>
</intent-filter>
</service>
<receiver android:exported="true"
android:name="MySMSBroadcastReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
If I test this on an Android Froyo device (emulator or real) this works as I expect. The MySMSBroadcastReceiver.onReceive(...) is being called when the device receives an SMS.
However if I install this on a 4.0 or 4.1 device (either emulator or a real device) nothing happens on an incoming message. No errors, no nothing. I also changed the properties for the project to target a 4.0 or 4.1 device specifically and re-installed it but that makes no difference.
After your application is installed, the user need to launch an activity of yours manually before any of your BroadcastReceivers will have an effect, as of Android 3.1.
You can start the receiver on OS startup giving the right permissions.
Related
I try to develop an Android application to handle the notifications from other apps and send them to my laptop to notify the user. I use the AccessibilityService to handle the notifications on devices with Android < 4.3 (API Level 18) and the NotificationListenerService for devices with android >= 4.3.
There are no issues getting the notifications on my only android device (Samsung Galaxy S with Android 2.3.3), but I need to activate the App in the accessibility settings.
Now I tried to debug the app on my Kindle Fire (API Level 17) and my apps Activity works fine, but the app is not listed in the accessibility settings of the device. The Amazon App testing service returns no problem, so I dont know where I should search the problem.
Is it possible to use the AccessibilityService on the Kindle Fire?
Here is my android manifest file:
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>
<uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18"
/>
<application
android:icon="#drawable/ic_launcher"
android:allowBackup="true">
<activity
android:name="de.test.notificationdistributor.SettingsActivity"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="de.test.notificationdistributor.NotificationDistributorService">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
<service
android:name="de.test.notificationdistributor.NotificationDistributionDeprService">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
</service>
</application>
You must add the permission android.permission.BIND_ACCESSIBILITY_SERVICE (added in API 16 - android 4.1)
<service
android:name="de.test.notificationdistributor.NotificationDistributorService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<meta-data android:name="android.accessibilityservice" android:resource="#xml/accessibilityservice" />
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
In the doc http://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html
Additionally an accessibility service must request the BIND_ACCESSIBILITY_SERVICE permission to ensure that only the system can bind to it. Failure to declare this intent will cause the system to ignore the accessibility service.
I have been trying to create an app service that does not have an Activity and i ran into some issues.
I want the service to run from boot, so naturally used a BroadcastReciever to catch ACTION_BOOT_COMPLETED this is no problem while testing. I used an Activity to start and stop the service to test it was working then rebooted to see if the boot receiver worked, it did, happy days.
Removed the test Activity and from the application and used the below manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- <activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> -->
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".SWKeepAliveService" />
</application>
</manifest>
Uninstalled then reinstalled the application, reboot the device and nothing. Tested it a few time with adb shell am broadcast -a android.intent.action.BOOT_COMPLETED, still nothing.
After some trial and error i figured out the broadcast receiver never receives the ACTION_BOOT_COMPLETED if the application has never run. Of course without a launcher, it would never run.
Have i missed something? I haven't seen any mention of this in the documentation.
EDIT 1
Ran some tests with my AOSP builds, the above manifest is fine on Gingerbread, but NOT on Jelly Bean. Something must have changed, i can only assume it's for security reasons (understandable). Though I haven't seen any documentation to support the fact.
Have i missed something?
Yes.
I haven't seen any mention of this in the documentation.
It was mentioned in the Android 3.1 release documentation, blog posts by balding guys, and a seemingly infinite number of answers here on StackOverflow.
Good day,
I have an application which connects my android device to an arduino unit through a service. I have managed to make the connection but it keeps asking me for permission to use the accessory whenever I plug it in. Is there any way to bypass this permission? It works perfectly with an intent filter if I do it through an activity, I have tried applying the same intent in the service but it does not seem to work :/.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="blink.service"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-feature android:name="android.hardware.usb.accessory" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".ActivityCreate">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".StartupIntent" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".MainService"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</service>
<uses-library android:name="com.android.future.usb.accessory"/>
</application>
</manifest>
Here is the code in my manifest.
Thanx
To bypass permission you must make your app a system app. To make an app run as a system app you must place the apk in system/app folder. For doing that i first remounted the system drive as rw (read-write) using adb using the following code:
adb remount rw
push "apk path" /system/app
adb remount ro
Now reboot the system. Android will no longer ask for permission.
I am developing an app which listens to incoming sms. I have added the permission:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
to my app manifest. And yes, it is not inside the receiver tag.
I am trying to test the app by sending a sms from one emulator to another. My logcat gets the following entry :
WARN/ActivityManager(66): Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) } to com.android.LUC requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)
The weird part is that when I am testing the app on emulator running android 3.2 it works fine!
App Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.sms"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:permission="android.permission.RECEIVE_SMS">
<activity android:name=".TestSMSReceiveActivity"
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=".mysmstestcall" android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
mysmstestcall is the broadcastreceiver class and TestSMSReceiveActivity is the main activity. The app fails to receive message in emulator running android 2.2. Please help!!
OK the problem is in your manifest. My working SMS broadcast receiver has the following manifest entry:
<receiver
android:name=".IncomingSmsBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
You do not need an android:permission attribute on the receiver. You just need the following permission to receive the broadcast and be able to look at the contents of the message:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
The thing most often missed is android:exported="true" when declaring the receiver which is required as you are receiving a broadcast that originates from outside your own application. Needless to say, the default for this property is 'false'. Happy SMS Receiving.
I have been able to create a *.apk file from my code, place the file
in IIS, and download it onto a number of Android phones. Upon the
install, the application works exactly as expected.
However, after a phone is rebooted, the application name is changed to
the fully-qualified Java class name of the activity in the menu (so
"MyActivity" becomes "com.mycompany.MyActivity"), and when I try to go
to Menu > Settings, I get an error that causes android to force close
my application.
Looking into DDMS, I see that I get an error indicating that it can
not find my Preferences activity, despite the fact upon initial
install, it works properly.
I'm using Eclipse on Windows XP, and have several Android devices at
my disposal to test with.
Any idea what's going on?
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.app"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/logo" android:label="#string/app_name"> <!--android:debuggable="true">-->
<activity android:name="com.company.app.ActivityMain"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.company.app.Preferences"
android:label="#string/app_settings">
<intent-filter>
<category android:name="android.intent.category.PREFERENCE"></category>
<action android:name="android.intent.action.MAIN"></action>
</intent-filter>
</activity>
<service android:name="com.company.app.Service"></service>
</application>
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
</manifest>
So I finally got this to work. I think that the package installer on the HTC Hero (and maybe the HTC Droid Eris) has some issues.
I uninstalled my application from the phone, changed the name of my main activity, and re-deployed it onto the Hero. I started to immediately get a "Force Close." I connected the device to DDMS and looked at the error. It was still looking for my old activity name. I factory reset the device and reinstalled the same package (with the updated name) and everything works as expected.
So it seems that the package installer is caching some part of the old manifest or something, not really sure what exactly is going on there. I may play with it some more if I get time.
I don't know if someone else could verify this problem, maybe it's something that should be taken up with HTC?
try to use this manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.app"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/logo" android:label="#string/app_name"> <!--android:debuggable="true">-->
<activity android:name=".ActivityMain"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Preferences"
android:label="#string/app_settings">
<intent-filter>
<category android:name="android.intent.category.PREFERENCE"></category>
<action android:name="android.intent.action.MAIN"></action>
</intent-filter>
</activity>
<service android:name=".Service"></service>
</application>
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
</manifest>