custom agreement

First look at a few examples, which can better illustrate the meaning of this article. If you are not interested in examples, you can go directly to the next stage of analysis.
Example on the PC side:
Enter Tencent://message/?uin=88888888 in the browser address bar, then press Enter, and found that you can chat with strangers in QQ. This function has been available for a long time.
Android example:
Friends who do Android development (of course, IOS also has similar functions) know that you can call system functions through intents, such as making calls:
Intent intent = new Intent(); 
intent.setAction(Intent.ACTION_CALL);  
intent. setData(Uri.parse("tel:15899996666")); 
startActivity(intent);
IOS example:
Apple's corporate account can download and install apps directly from the company's website through a protocol without downloading through the AppStore, such as Add the following code to the html page: <a href="itms-services://?action=download-manifest&url=http://192.168.0.100:8080/latest/testapp.plist (address of the plist file)"> Install the application</a>, then open it through a browser, click it, and find that the application can be downloaded directly.


After reading the three examples, careful friends may find that the programs executed on the three platforms all use a pattern of addresses, such as:
1. Tencent://message/?uin=88888888; Tencent's own implementation of the protocol, only QQ Can parse what this command does
2. tel: 15899996666; the protocol implemented by the system, you can make calls after the APP is called
3. itms-services://?action=download-manifest&url=http://192.168.0.100:8080/latest/testapp.plist Apple The protocol implemented by yourself can bypass the AppStore to download the APP from other websites after calling, and install

the one that everyone is more familiar with is http://www.baidu.com, but what is the above? They are similar, and they are also protocol calls. The mode is: protocol://command? parameter name = parameter value. These protocols can be supported by the system by default (http, tel), or user-defined (tencent, itms- services), for Windows, Linux and OS X operating systems all support custom protocols, custom protocols can help users to implement application A to call application B on the same system, for example, QQ can be called directly in the browser, and APP uses the tel protocol to call the system Call function.

The following is how each operating system implements the custom protocol:
A protocol is a method that is used to send, receive, and handle information over a connection. Common protocols viewed from the browser include http, ftp, and mailto. In order for you to view information sent over a specific protocol, it must be registered. Once registered, the protocol can then be handled by the program you specify, such as your browser or a 3rd party viewer. This means that a hyperlink ( e.g. foo://fred ) can use the handler for protocol foo to open the file named fred.

Contents [hide]
1 Registering an unsupported protocol
1.1 Windows
1.2 Linux
1.3 OS X
2 Redirecting a registered protocol



[edit]Registering an unsupported protocol
Mozilla products utilize protocols defined internally, as well as those defined by the operating system. You can add the ability to use an unsupported protocol by registering it. The OS-specific method of doing this is described below.

[edit]Windows
Create the registry .reg file, replacing foo with your unregistered protocol, and the path with whatever handler program you want to run. Then merge it into the Windows registry.


REGEDIT4

[HKEY_CLASSES_ROOT\foo]
@="URL:foo Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\foo\shell]

[HKEY_CLASSES_ROOT\foo\shell\open]

[HKEY_CLASSES_ROOT\foo\shell\open\command]
@="\"C:\\Program Files\\Application\\program.exe\" \"%1\""
See Registering an Application to a URL Protocol for additional information.

[edit]Linux
Registration is unnecessary. Simply associate whatever proto: with a program through Firefox: Example: Add the sip: protocol to launch kphone for VoIP calls in Firefox:

- Type about:config into the address bar
- Right-click create new boolean value: network.protocol-handler.external.sip and set to true
- Right-click create new boolean value: network.protocol-handler.warn-external.sip and set to false
- Right-click create new string value: network.protocol-handler.app.sip and set to /usr/bin/kphone
This will actually launch kphone. Not sure if it will dial though. That is untested :)

You can also optionally register the protocol with whatever window manager you are using. In KDE this is done through Control Center - KDE Components - File Associations. This step is usually unnecessary unless your window manager has a custom browser, such as konqueror.

[edit]OS X
Probably very similar to Linux (above).

[edit]Redirecting a registered protocol
If the protocol is already handled by the browser, you can specify what program will be used as a handler to open the file. To do this, add the pref:
network.protocol-handler.app.foo as a string with value C:\Program Files\Application\program.exe
Note: If the path or name is incorrect, the browser will display an error saying "protocol (foo) isn't associated with any program". (See bug 312953).

You may also need to use the following prefs, although this is uncertain:
network.protocol-handler.external.foo = true
network.protocol-handler.expose.foo = false

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326495039&siteId=291194637