For example, to implement File Association, you must first modify AndroidManifest. xml. The example is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. android. sample" android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
<Application android: icon = "@ drawable/icon" android: label = "@ string/app_name"
Android: debuggable = "true">
<Activity android: name = ". MainActivity"
Android: configChanges = "orientation | keyboardHidden | navigation"
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 = ". OtherActivity"
Android: configChanges = "orientation | keyboardHidden | navigation"/>
<Activity android: name = ". AssociatedActivity"
Android: configChanges = "orientation | keyboardHidden | navigation">
<Intent-filter>
<Action android: name = "android. intent. action. VIEW"/>
<Category android: name = "android. intent. category. DEFAULT"/>
<Data android: mimeType = "text/plain"> </data>
<Data android: mimeType = "application/epub + zip"> </data>
</Intent-filter>
</Activity>
</Application>
<Uses-sdk android: minSdkVersion = "8"/>
<Uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/>
<Uses-permission android: name = "android. permission. INTERNET"/>
</Manifest>
In this example, there are two "intent-filter", the first is the first activity started by the application, and the second "intent-filter" is used to implement File Association.
<Intent-filter>
<Action android: name = "android. intent. action. VIEW"/>
<Category android: name = "android. intent. category. DEFAULT"/>
<Data android: mimeType = "text/plain"> </data>
<Data android: mimeType = "application/epub + zip"> </data>
</Intent-filter>
In this xml section, the program is registered to be associated with the txt and epub file formats. If jpeg is to be associated, mimeType is changed to: "image/jpeg", and the association with all files is changed: "*/*". In this way, when you click related files in the File Manager, the system will attempt to execute your program.
Public class AssociatedActivity extends Activity {
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
Intent intent = getIntent ();
String action = intent. getAction ();
If (intent. ACTION_VIEW.equals (action )){
Uri uri = (Uri) intent. getData ();
String filename = uri. getPath ();
Log. e ("info", filename );
}
}
}
Here, the action mainly determines whether the VIEW action corresponds to android. intent. action. VIEW in xml. You can obtain the passed parameters through intent. getData, that is, the clicked file.
From chenghai2011