SecurityException: Not allowed to start service Intent without permission

4,608 views
Skip to first unread message

Arnaud VALLAT

unread,
Apr 23, 2012, 11:18:32 AM4/23/12
to androi...@googlegroups.com
Hello,

I'm getting this error:

java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE

But I think I have the correct permission setup in my manifest:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

In fact, I have only this error on 1 device running Android 2.3.7. Unfortunately, I don't have access to this device...

(I'm using the chrome2phone code base for c2dm.)

Any idea of why I'm getting this error?


Regards


Rno

Mark Murphy

unread,
Apr 23, 2012, 11:34:11 AM4/23/12
to androi...@googlegroups.com
You might want to post your full manifest, so we can confirm you have
the <uses-permission> element in the right place.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_ Version 2.6
Available!

Arnaud VALLAT

unread,
Apr 23, 2012, 11:43:59 AM4/23/12
to androi...@googlegroups.com
Thank you for this quick reply, please find bellow my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
      package="com.foo.bar.baz"
      android:versionCode="42"
      android:versionName="4.2"
      android:installLocation="internalOnly">

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="11" />

    <supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"
android:xlargeScreens="true" />

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />

    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

    <uses-permission android:name="android.permission.READ_SYNC_STATS" />
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <permission
android:name="com.foo.bar.baz.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

    <uses-permission
android:name="com.foo.bar.baz.permission.C2D_MESSAGE" />

    <uses-permission
android:name="com.google.android.c2dm.permission.RECEIVE" />

    <uses-permission
android:name="android.permission.WAKE_LOCK" />

    <application
    android:icon="@drawable/app"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"
    android:theme="@style/Theme">

    <activity
android:name=".ui.HomeActivity"
    android:launchMode="singleTop">

    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    </activity>

<!--

-->

        <service
            android:name=".c2dm.Receiver" />

<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.foo.bar.baz" />
            </intent-filter>

            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.foo.bar.baz" />
            </intent-filter>

        </receiver>

    </application>
</manifest>


On Monday, April 23, 2012 5:34:11 PM UTC+2, Mark Murphy (a Commons Guy) wrote:
You might want to post your full manifest, so we can confirm you have
the <uses-permission> element in the right place.

Mark Murphy

unread,
Apr 23, 2012, 11:48:06 AM4/23/12
to androi...@googlegroups.com
Well, that looks fine. This exception is stemming from your code?

Arnaud VALLAT

unread,
Apr 23, 2012, 3:16:39 PM4/23/12
to androi...@googlegroups.com
Yep, I'm in the stack trace. Here it comes:

java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
        at android.app.ContextImpl.startService(ContextImpl.java:864)
        at android.content.ContextWrapper.startService(ContextWrapper.java:336)
        at com.google.android.c2dm.C2DMessaging.register(C2DMessaging.java:53)
        at com.foo.bar.baz.ui.HomeActivity.onResume(HomeActivity.java:178)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
        at android.app.Activity.performResume(Activity.java:3832)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2231)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2256)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1789)
        at android.app.ActivityThread.access$1500(ActivityThread.java:123)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3835)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
        at dalvik.system.NativeStart.main(Native Method)

Thanks for your help!

Rno

On Monday, April 23, 2012 5:48:06 PM UTC+2, Mark Murphy (a Commons Guy) wrote:
Well, that looks fine. This exception is stemming from your code?

Deejo

unread,
Aug 13, 2013, 2:32:15 AM8/13/13
to androi...@googlegroups.com
Hi Arnuad, 

Did you get any solution on this? Kindly let me know if you got any solution. I'm facing same issue. On Stack overflow one persion has mentioned that he just re create project and it worked (without change anything)

Regards-
Dipak Jotaneeya
Message has been deleted

Danny Hvam

unread,
Jun 3, 2015, 3:48:39 AM6/3/15
to androi...@googlegroups.com
Is there any news on this?
I'm facing the same issue, for me it occours on a Sony Xperia Z1 Compact D5503 (Android 5.0.2). I've only got the error on this specific device, but unfortunately I do not have access to the device. My first thought was, that it might have something to do with proguard, but it't not a rooted device, so it seems unlikely.

Amit Patoliya

unread,
Jun 3, 2015, 5:03:56 AM6/3/15
to androi...@googlegroups.com
try with lower targat api 19 or 20, if its 22 

--
You received this message because you are subscribed to the Google Groups "android-c2dm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-c2dm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Amit Patoliya
Android Developer at 
SpaceO Infoweb solutions

Danny Hvam

unread,
Jun 3, 2015, 5:35:52 AM6/3/15
to androi...@googlegroups.com
Currently my build.gradle is like this:

compileSdkVersion 22
minSdkVersion 10
targetSdkVersion 19

I can try compiling against a lower version - but cannot confirm before releasing it to production, as I cannot seem to reproduce it myself and it only happens very rarely.
I've created a SO with some details: http://stackoverflow.com/questions/30615983/android-java-lang-securityexception-despite-having-declared-uses-permission
Reply all
Reply to author
Forward
0 new messages