0

In reading the Android documentation on Device Administration, it says to set it up as follows:

<activity android:name=".app.DeviceAdminSample" ... ></activity>

<receiver android:name=".app.DeviceAdminSample$DeviceAdminSampleReceiver" ... ></receiver>

public class DeviceAdminSample extends DeviceAdminReceiver { ... }

When setting it up on my application, on the receiver name, Studio gave a "Cannot resolve symbol" error on the ...$DeviceAdminSampleReceiver" part, so I set my receiver name and class name as "MyDeviceAdminReceiver"

The receiver name in the example doesn't match the Device Administration Receiver class name. What's the significance of the dollar sign? Why does the example have a different name for the receiver and the receiver class?

VikingGlen
  • 1,705
  • 18
  • 18
  • 1
    The "$" indicates an inner class in Java notation. I suspect that some of the Android tooling is not prepared to deal with inner classes. I suggest just using top-level classes. – EJK Jan 25 '16 at 15:53
  • 1
    BTW, you should make your question more clear by (a) specifying exactly what documentation your are referencing, (b) explain what you mean by "Studio choked". – EJK Jan 25 '16 at 15:54
  • I made the changes you requested. I don't have the receiver set up as an inner class, which would explain the error. Your response answered other questions I had about properly setting up inner class receivers in AndroidManifest.xml. – VikingGlen Jan 25 '16 at 16:55
  • Just to close the loop on this, I have posted the above as an answer, with a few additional details. – EJK Jan 25 '16 at 18:29

1 Answers1

2

The "$" syntax indicates that DeviceAdminSampleReceiver is an inner class of DeviceAdminSample. This is Java notation.

The documentation link you posted, refers to a sample that is distributed with the Android SDK:

SDK_ROOT/ApiDemos/app/src/main/java/com/example/android/apis/app/DeviceAdminSample.java

In this sample, you can see that the above class relationship is the case:

public class DeviceAdminSample extends PreferenceActivity {
   ...
   public static class DeviceAdminSampleReceiver extends DeviceAdminReceiver {
   ...
   }
}

Thus if you want to follow the same pattern as the example, then you must have the same inner-class relationship. Although nothing in Android requires you to do this. You simply need to make sure that the receiver element in your manifests points at an existing class (be it inner or not).

EJK
  • 12,332
  • 3
  • 38
  • 55
  • Also for the sake of closure; I moved my DeviceAdminSampleReceiver to an inner class of my primary activity. Studio recognized it immediately and auto filled in the name, dollar sign and all, when I set it up as a receiver. :) – VikingGlen Jan 26 '16 at 01:27