cafffiene wrote:
> Having trouble with permissions. The error I get is this:
>
> Not allowed to start service Intent { comp=
> {com.commonsware.android.service/
> com.commonsware.android.service.WeatherPlusService} } without
> permission private to package
>
> I installed the WeatherPlus app from Mark Murphy's dev book.
That sounds vaguely familiar...
> I'm
> trying to call his weather service from a different app. I think I
> have an issue with permissions, not really sure how they work.
I obviously failed with my Permissions chapter. :-(
> <?xml version="1.0" encoding="utf-8"?>
> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
> package="com.punchcut.isender1"
> android:versionCode="1"
> android:versionName="1.0">
> <permission
> android:name = "com.commonsware.android.service.mypermission"
> android:label = "" />
> <uses-permission android:name="android.permission.INTERNET" />
> <application android:icon="@drawable/icon" android:label="@string/
> app_name">
> <uses-permission
> android:name="com.commonsware.android.service.mypermission" />
> <activity android:name=".ISender1"
> android:label="@string/app_name">
> <intent-filter>
> <action android:name="android.intent.action.MAIN" />
> <category
> android:name="android.intent.category.LAUNCHER" />
> </intent-filter>
> </activity>
> <uses-permission
> android:name="android.permission.ACCESS_BACKGROUND_SERVICE" />
>
> </application>
> <uses-sdk android:minSdkVersion="3" />
> </manifest>
>
>
>
>
>
> <?xml version="1.0" encoding="utf-8"?>
> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
> package="com.commonsware.android.service">
>
> <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" />
> <application android:label="@string/app_name">
> <activity android:name=".WeatherPlus" 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=".WeatherPlusService">
> <uses-permission
> android:name="com.commonsware.android.service.mypermission"/>
> </service>
> </application>
> </manifest>
You have a few problems here:
1. The <permission> element needs to be in the application that is being
secured. In this case, it would be in the application implementing the
service, not the activity trying to use the service.
2. To protect a service with that permission, you use an
android:permission attribute in the <service> element:
http://developer.android.com/guide/topics/manifest/service-element.html
You do not use <uses-permission> in the service for the permission in
question to indicate what should be protected.
3. For your activity trying to access the protected service, your
<uses-permission> element needs to be a child of <manifest>:
http://developer.android.com/guide/topics/manifest/uses-permission-element.html
You have the "mypermission" <uses-permission> as a child of
<application>, if I am reading your XML correctly.
4. Unless you significantly modified WeatherPlusService, it is not a
remote service, and therefore cannot be accessed by an outside
application. Remote services are covered in _The Busy Coder's Guide to
*Advanced* Android Development_, and I use different sample applications
there.
If you have further questions about the book examples, consider hopping
over to the cw-android Google Group:
http://groups.google.com/group/cw-android
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Need Android talent? Ask on HADO! http://wiki.andmob.org/hado
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---