What kind of case can I omit? - android

The following code works well, I often find some sample code to omit, so I change my code as
<service android:name=".MyInternetServer"></service>
but I get an error "The service can't be found".
I guess the package="com.example.enabledisablebroadcastreceiver" and
<service android:name="com.code4reference.enabledisablebroadcastreceiver.MyInternetServer"></service>,
maybe it should be use full name, right?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.enabledisablebroadcastreceiver"
android:versionCode="1"
android:versionName="1.0" >
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.code4reference.enabledisablebroadcastreceiver.EnableDisableBroadcastReceiver"
android:label="#string/title_activity_enable_disable_boradcast_receiver" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Broadcast receiver -->
<receiver android:name="com.code4reference.enabledisablebroadcastreceiver.AlarmManagerBroadcastReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<service android:name="com.code4reference.enabledisablebroadcastreceiver.MyInternetServer"></service>
</application>
</manifest>

The shorthand "dot" notation in the Manifest file works as described in the documentation:
However, as a shorthand, if the first character of the string is a
period, the string is appended to the application's package name (as
specified by the <manifest> element's package attribute).
So in your case, using:
.MyInternetServer
...is shorthand for:
com.example.enabledisablebroadcastreceiver.MyInternetServer
as that's what's in your <manifest>'s package attribute.
I'm guessing you probably want to update your manifest's package attribute to match the package you're actually using for your project.

Yes give your service a full path, where its actually located with full package name and then check, it will work.

Related

In Android XML, what is the significance of a period (".") preceding a class or package reference?

While browsing the Android developer docs I spotted example code where references to classes/packages are preceded by periods.
In the snippet below from http://developer.android.com/guide/topics/search/search-dialog.html there is ".SearchableActivity"
<application ... >
<activity android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
...
</application>
Another example - http://developer.android.com//training/sharing/receive.html - has ".ui.MyActivity"
<activity android:name=".ui.MyActivity" >
What do these preceding "." imply, and when/why should/would you use one? What happens if they are ommited?
android:name
Quoting docs
The name of the class that implements the activity, a subclass of
Activity. The attribute value should be a fully qualified class name
(such as, "com.example.project.ExtracurricularActivity"). However, as
a shorthand, if the first character of the name is a period (for
example, ".ExtracurricularActivity"), it is appended to the package
name specified in the element. Once you publish your
application, you should not change this name (unless you've set
android:exported="false").
If in manifest you have
package="com.example.layout"
And your Activity is under the same package you can have
<activity
android:name=".ActivityName"
Instead of ShortHand You can also have
<activity
android:name="com.example.layout.ActivityName"
If the activity is not declared right in manifest you end up in ActivityNotFoundException
If your activity is in a different package then you mention the fully qualified class name
<activity
android:name="packagename.ActivityName"
Note: There is no default. The name must be specified.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".DownloadActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
See the above example manifest file
Here "." means a package name
means following line
<activity android:name=".DownloadActivity" >
you can write 2 ways
<activity android:name="com.example.DownloadActivity" > and
<activity android:name=".DownloadActivity" >
in your manifest file you already declare the base package name on top
package="com.example"
so android gives us a way to make it short
so if you use "." for class names it will take the package name that you have defined on top of the manifest file and system take it as com.example.DownloadActivity

No launcher activity found.! The launch will only sync the application package on the device.!

I am facing the problem plzzz help me out. Here is my manifest.xml file.
Plz help me out.......your help is highly appreciated....
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hello.myandroidnew"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myandroidnew.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".second"/>
</application>
</manifest>
Change your intent filter to the following:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The difference is the action. It must be android.intent.action.MAIN in order to be listed in the launcher.
You have to set the action name properly so that android know that it is the main activity. Change
<action android:name="android.intent.action.MAINACTIVITY" />
to
<action android:name="android.intent.action.MAIN" />
update:-
You specify name of the class in
<activity
android:name="com.example.myandroidnew.MainActivity"
Docs of "android.intent.action.MAIN" specifies :-
public static final String ACTION_MAIN
Added in API level 1
Activity Action: Start as a main entry point, does not expect to receive data.
Input: nothing
Output: nothing
Constant Value: "android.intent.action.MAIN"
Thus you can see that action.MAIN tells android that it is the main entry point i.e. the default activity that is to be shown when the app starts.

How to parse xml file in vim?

I am currently working on an android project. And now i wish to complete a job: Parsing a xml file called AndroidManifest.xml and get some attribute from it. And set to some values in vim.
Here is the AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.base.module.callhistory"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar"
android:icon="#drawable/call_history">
<activity android:name="HistoryMainActivity"
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="HistoryListActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="DetailListActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
I want to parse package="com.base.module.callhistory" and HistoryListActivity in <activity android:name="HistoryMainActivity". Then i can use this two value to compose a command to launch my app automatically. I just set these values by hand. But i think if vim can parse this file and set these values automatically, it's must very cool.
Consider xmlstarlet, xmllint --xpath
Otherwise, you can use perl or python to achieve your goal if you have it compiled in (usually packaged versions do)
Regardless of that, you might still use nomarl search (/) patterns with c i t to replace the tag contents
I had a similar requirement as you, and I just wrote a custom python script for this task.

Android C2DM and lib project

I'm currently working on a libproject (Android) that should be included inside a few other applications.
Everything is working fine now that I've been struggling a bit with Activities and Manifests, exept for the C2DM bit.
I can invoke my different classes fine, but I can't seem to catch the registration ID (or of course actual messages, but that must be the same problem...)
I think the problem is coming from the filtering in my manifest(s), so if anyone has any advice for me, that would be really helpful.
Here is a copy of receiver part of my manifest (from the apps, not the library, but it's actually just a copy), but it's pretty straighforward. I just want to know how I should adapt it in order to invoke the right class in the lib...
<!--
Only C2DM servers can send messages for the app. If permission is
not set - any other app can generate it
-->
<receiver
android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.myapp.lib" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.myapp.lib" />
</intent-filter>
</receiver>
Where com.myapp.lib is my lib package name, and the receiver is in a package named the same (in the lib project, of course).
Thanks in advance for the help, and don't hesitate to ask for furthers details :)
Edit :
I tried with only the lib registered on google C2DM, and also with both app and lib. Same problem
There is a better way of using your C2DM from a library project by using the intent-filter.
The manifest file is the one from the app.
The package for the lib is com.mylib and the one for the app is com.myapp.
There is 2 things to change from the lib manifest.
The classpath used in permissions.
The intent-filter package.
Both should be you app package and not your lib package.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps" android:required="true"/>
<activity
android:name=".MyActivity"
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="com.mylib.C2DMRegistrationReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" >
</action>
<category android:name="com.myapp" />
</intent-filter>
</receiver>
<receiver
android:name="com.mylib.C2DMMessageReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" >
</action>
<category android:name="com.myapp" />
</intent-filter>
</receiver>
</application>
</manifest>
Answer, is anyone stumble upon the same problem...
In the google.android.c2dm package, class C2DMBaseReceiver, method runIntentInService, change
String receiver = context.getPackageName() + ".C2DMReceiver"
with the fully qualified name.. and there you go :)
The manifest looks fine. In your package you should have a class called C2DMReceiver and it should extend C2DMBaseReceiver. This class and the overridden methods it contains are then called upon successful registration and when a message is received. I have written a very basic example of this that may be helpful for you to refer to here

Android Package structure

My default package name is com.xont.controller (R file contain that package.Eclipse generated one) . I want to make it more packages.Like 'com.xont.controller.salesand 'com.xont.controller.admin like this: And I added activity also in manifestfile
Edited
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.xont.controller"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:label="Xont" android:icon="#drawable/virtusel64">
<activity android:name=".AndroidAppXontActivity"
android:label="Xont">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"
android:label="Login">
</activity>
<activity android:name=".syn.DatabaseCheckActivity"
android:label="Databse Setup">
</activity>
...........
Package structure is:
Error says : android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xont.controller/com.xont.controller.syn.DatabaseSetupActivity}; have you declared this activity in your AndroidManifest.xml?
Please help me what i want to do here.
All components that are registered as .SomeName use manifest's package value as prefix. So basicaly you regsitered activity .AndroidAppXontActivity as com.android.xont.controller.AndroidAppXontActivity. But there is no such java class.
You should fix your component names to have full name to your Java class, like this:
<activity android:name="com.xont.controller.AndroidAppXontActivity" ... />
Same for all other components.
Please try this,
<activity android:name="com.xont.controller.syn.DatabaseSetupActivity"
android:label="Databse Setup">
</activity>

Categories

Resources