[TinyTut] - Replacing System Application (i.e. Maps)

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

[TinyTut] - Replacing System Application (i.e. Maps)

Postby plusminus » Fri May 16, 2008 7:51 pm

[align=center][TinyTut] - Replacing System Application (like Maps)[/align]

What you learn: You will learn how to catch/replace the System Applicatio for example the Maps-Activity.

:idea: Designed/Tested with sdk-version: m5-rc15

Difficulty: 1.5 of 5 :)

:idea: Questions/Problems: Simply post below...

Description:
  1. Create a standard application as always
  2. Search for the Activity you want in the dump of the Android internal XML-files (load it :src: Android - Internal XML dumped)
    • As we want to replace the Maps Activity we search for sth. like "Maps" and in /android-system-apks/Maps/AndroidManifest.xml" we find what we want.
    Syntax: [ Download ] [ Hide ]
    Using xml Syntax Highlighting
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest
    3.         xmlns:android="http://schemas.android.com/apk/res/android"
    4.         android:sharedUserId="com.google.android.core"
    5.         android:signature="com.google"
    6.         package="com.google.android.maps">
    7.          
    8.         <permission
    9.                 android:label="@string/read_perm_label"
    10.                 android:name="com.google.android.maps.permission.READ_MY_MAPS"
    11.                 android:description="@string/read_perm_desc" />
    12.         ....
    13.         <uses-permission android:name="android.permission.ACCESS_GPS" />
    14.         ....
    15.          
    16.         <application
    17.                 android:theme="@android:style/Theme.Dark"
    18.                 android:icon="@drawable/ic_launcher_maps"
    19.                 android:taskAffinity="com.google.android.maps">
    20.                  
    21.                 <activity
    22.                         android:label="@string/maps_label"
    23.                         android:name="Maps"
    24.                         android:launchMode="singleTop">
    25.                                 ....
    26.                         <!-- THIS IS WHAT WE WANT -->
    27.                         <intent-filter android:label="@string/google_maps_label">
    28.                                 <action android:name="android.intent.action.VIEW" />
    29.                                 <category android:name="android.intent.category.DEFAULT" />
    30.                                 <category android:name="android.intent.category.BROWSABLE" />
    31.                                 <data android:scheme="geo" />
    32.                         </intent-filter>
    33.                         <!-- UP TO HERE -->
    34.                         ....
    35.                 </activity>
    36.         ....
    37.         </application>
    38. </manifest>
    Parsed in 0.004 seconds, using GeSHi 1.0.8.4
  3. Open your own AndroidManifest.xml and register the Activity you want your app to listen to it in the AndroidManifest.xml in the following way:
    Syntax: [ Download ] [ Hide ]
    Using xml Syntax Highlighting
    1.         ...
    2.         <activity class=".MyJustCreatedApplication" android:label="@string/app_name">
    3.                 <intent-filter>
    4.                         <action android:name="android.intent.action.VIEW" />
    5.                         <category android:name="android.intent.category.DEFAULT" />
    6.                         <category android:name="android.intent.category.BROWSABLE" />
    7.                         <data android:scheme="geo" />
    8.                 </intent-filter>
    9.         </activity>
    10.         ...
    Parsed in 0.002 seconds, using GeSHi 1.0.8.4
  4. Run the app once and close it (just that it gets installed on the emulator).
  5. The next time an Intent with a "geo"-uri scheme is broadcasted our app will get started or at least...
  6. The system will ask you which one of two available activities you want to use to handle the VIEW-Action on the "geo"-scheme:
    - the 1st one is the "Maps" standard system activity
    - the 2nd one should be yours
  7. Test this it with another app that executes the following line:
    Syntax: [ Download ] [ Hide ]
    Using java Syntax Highlighting
    1. startActivity(new Intent(android.content.Intent.VIEW_ACTION, Uri.parse("geo:49.473367,8.660274")));
    Parsed in 0.031 seconds, using GeSHi 1.0.8.4

[align=center]Thats it :)[/align]
Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby cabernet1976 » Mon May 19, 2008 12:22 pm

Hi plusminus,

Very good toturials, I rated it 5 stars.
Thanks.
Upload2Flickr's blog: http://upload2flickr.blogspot.com
cabernet1976
Senior Developer
Senior Developer
 
Posts: 154
Joined: Fri Nov 16, 2007 2:34 am
Location: China

Postby rmeph » Sat May 24, 2008 1:15 pm

can we add custom menu item in Maps application?????
rmeph
Senior Developer
Senior Developer
 
Posts: 121
Joined: Mon Dec 10, 2007 1:54 pm
Location: India

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 7 guests