{"id":184738,"date":"2013-06-27T11:16:03","date_gmt":"2013-06-27T07:16:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=184738"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=184738","title":{"rendered":"<span class=\"post_title\">\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 cURL \u043d\u0430 android<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/162\/b5c\/6fe\/162b5c6feccc025d10e823820b4b1ac8.png\"\/><\/p>\n<h4>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e<\/h4>\n<p>  \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 API \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 C++, \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432\u043e \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u043c\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043f\u043e\u0434 android.<\/p>\n<p>  Libcurl \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 API \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b; <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a \u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u0430\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 libcurl. libcurl \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 (\u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e URL) \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c (\u043a\u0430\u043a \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c, \u0442\u0430\u043a \u0438 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u0438\u043c). (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Main_Page\">wikipedia<\/a>)<\/p>\n<p>  \u0414\u043b\u044f iOS \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u0441 \u0441\u0430\u0439\u0442\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u0418 \u0441 iOS \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>  \u041f\u043e\u0434 android \u043c\u043d\u0435 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 google \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430, \u0433\u0434\u0435 \u0431\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u044d\u0442\u043e\u0439 \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435. (\u041c\u043e\u0436\u0435\u0442 \u044f \u043f\u043b\u043e\u0445\u043e \u0438\u0441\u043a\u0430\u043b).<\/p>\n<p>  \u0418 \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u043f\u043e\u0434 android \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0447\u0435\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h5>\u0427\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/h5>\n<p>  <\/p>\n<ul>\n<li> \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 android <a href=\"http:\/\/www.eclipse.org\/downloads\/\">Eclipse<\/a>;<\/li>\n<li> <a href=\"http:\/\/developer.android.com\/tools\/sdk\/ndk\/index.html\">ndk<\/a> \u0438 \u0443\u043c\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c;<\/li>\n<li> \u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434 android \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"http:\/\/curl.haxx.se\">cURL<\/a>.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u0434\u043b\u044f android<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u0439\u0442\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442 <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u0438 \u0437\u0430\u0439\u0442\u0438 \u0432 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u0442\u043e \u0442\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0435\u043d\u043d\u044b\u0439 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a (Android 7.31.0 binary SSL) \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0438\u0434\u0438\u043c\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u043d\u0443\u044e \u0443\u0442\u0438\u043b\u0438\u0442\u0443 \u0438\u0437 \u043f\u043e\u0434 \u0434\u0435\u0432\u0430\u0439\u0441\u0430. \u041d\u043e \u043e\u043d \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u0435\u043d, \u0435\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0438\u0437 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <br \/>  \u0425\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"http:\/\/thesoftwarerogue.blogspot.ru\/2010\/05\/porting-of-libcurl-to-android-os-using.html\">\u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b<\/a>, \u043a\u0430\u043a \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u0443\u044e \u0434\u043b\u044f ndk *.a \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. <\/p>\n<p>  \u0415\u0441\u0442\u044c \u043f\u0440\u043e \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u043f\u043e\u0434 android \u0438 \u043d\u0430 <a href=\"http:\/\/habrahabr.ru\/post\/158743\/\">\u0445\u0430\u0431\u0440\u0435<\/a>. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0436\u0435\u043b\u0430\u043d\u043d\u044b\u0439 *.a \u0444\u0430\u0439\u043b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438. \u0421\u0430\u043c \u044f \u0435\u0433\u043e \u043d\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u043b. \u042f \u0435\u0433\u043e \u0447\u0435\u0441\u0442\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u043b.<\/p>\n<h4>\u0414\u0430\u043b\u044c\u0448\u0435<\/h4>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u0441\u044e \u043c\u043e\u0449\u044c <a href=\"http:\/\/developer.android.com\/tools\/sdk\/ndk\/index.html\">ndk<\/a> \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u0439.  <\/p>\n<h5>Java \u0447\u0430\u0441\u0442\u044c \u0447\u0430\u0441\u0442\u044c<\/h5>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c MainActivity \u0441 \u043e\u0434\u043d\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439 \u0438 \u043f\u043e\u043b\u0435\u043c \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0430\u0434\u0440\u0435\u0441\u0430 \u0441\u0430\u0439\u0442\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p>  <b>activity_main.xml<\/b>:  <\/p>\n<pre><code class=\"xml\">&lt;RelativeLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;     xmlns:tools=&quot;http:\/\/schemas.android.com\/tools&quot;     android:layout_width=&quot;match_parent&quot;     android:layout_height=&quot;match_parent&quot;     android:paddingBottom=&quot;@dimen\/activity_vertical_margin&quot;     android:paddingLeft=&quot;@dimen\/activity_horizontal_margin&quot;     android:paddingRight=&quot;@dimen\/activity_horizontal_margin&quot;     android:paddingTop=&quot;@dimen\/activity_vertical_margin&quot;     tools:context=&quot;.MainActivity&quot; &gt; \t    &lt;EditText \t       android:id=&quot;@+id\/server_url&quot; \t       android:text=&quot;@string\/default_url&quot; \t       android:hint=&quot;@string\/server_url_hint&quot; \t       android:layout_width=&quot;match_parent&quot; \t        android:layout_height=&quot;wrap_content&quot; \t       android:singleLine=&quot;true&quot;\/&gt;       \t   \t&lt;Button android:id=&quot;@+id\/button_curl_call&quot; \t   \t    android:layout_below=&quot;@+id\/server_url&quot; \t       \t\tandroid:layout_width=&quot;wrap_content&quot; \t        \tandroid:layout_height=&quot;wrap_content&quot; \t           android:layout_alignParentRight=&quot;true&quot; \t           android:text=&quot;@string\/button_curl&quot; \t           android:layout_gravity=&quot;right&quot; \t           \/&gt;     \t    &lt;TextView \t        android:id=&quot;@+id\/text&quot; \t        android:layout_below=&quot;@+id\/button_curl_call&quot; \t        android:layout_weight=&quot;1&quot; \t        android:layout_width=&quot;fill_parent&quot; \t        android:layout_height=&quot;fill_parent&quot; \t    \/&gt; &lt;\/RelativeLayout&gt; <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/ecc\/650\/9f4\/ecc6509f4d1f665819ae807303eb610d.png\"\/><\/p>\n<p>  <b>MainActivity.java<\/b>  <\/p>\n<pre><code class=\"java\">package com.ifree.ndkNative;  import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;  public class MainActivity extends Activity { \tprivate static final String INTENT_HTML_DATA = &quot;.html_data&quot;; \tpublic static final int HANDLE_CALLBACK = 0; \tfinal private Handler handler = new Handler() {          @Override         public void handleMessage(Message msg) {             switch (msg.what) {                 case HANDLE_CALLBACK:                 \tString html = msg.getData().getString(INTENT_HTML_DATA);                 \tSetHtmlText(html);                     break;             }         }     };     \t     private void SetHtmlText(String html){     \tTextView tv = (TextView) findViewById(R.id.text);     \ttv.setText(html);     }      \t\/** Called when the activity is first created. *\/ \t    @Override \t    public void onCreate(Bundle savedInstanceState) { \t        super.onCreate(savedInstanceState); \t        setContentView(R.layout.activity_main); \t         \t        final EditText serverUrl = (EditText) findViewById(R.id.server_url); \t         \t        Button btnCurl = (Button) findViewById(R.id.button_curl_call); \t        btnCurl.setOnClickListener(new OnClickListener() { \t\t\t\t@Override \t\t\t\tpublic void onClick(View v) { \t\t\t\t\tNative curl = new Native(); \t\t\t        curl.addCurlCallbackListener(new ICurlCallbackListener() { \t\t\t\t\t\t@Override \t\t\t\t\t\tpublic void curlCallBack(String callback) { \t\t\t\t\t\t\t\/\/\u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c gui \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0432 TextView, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c handler \t\t\t\t\t\t\tBundle bundle = new Bundle(); \t\t\t\t\t\t\tbundle.putString(INTENT_HTML_DATA, callback); \t\t\t\t\t\t\tMessage message = handler.obtainMessage(); \t\t\t\t\t\t\tmessage.setData(bundle); \t\t\t\t\t\t\thandler.sendMessage(message); \t\t\t\t\t\t} \t\t\t\t\t}); \t\t\t        String response = curl.get_text_from_cpp(String.valueOf(serverUrl.getText()));\/\/\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0421++ \u0447\u0430\u0441\u0442\u0438 \t\t\t\t} \t\t\t});    \t    } } <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441 <b>Native.java<\/b>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0421++ \u043a\u043e\u0434\u0443.  <\/p>\n<pre><code class=\"java\">package com.ifree.ndkNative;  import java.util.HashSet;  public class Native { \tprivate HashSet&lt;ICurlCallbackListener&gt; callBackListeners = new HashSet&lt;ICurlCallbackListener&gt;(); \t \tpublic void addCurlCallbackListener(ICurlCallbackListener listener){ \t\tcallBackListeners.add(listener); \t} \t \tpublic void removeCurlCallbackListener(ICurlCallbackListener listener){ \t\tcallBackListeners.remove(listener); \t} \t \tstatic { \t       System.loadLibrary(&quot;ndkNative&quot;); \t    }  \t\/\/(\u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e native \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 C++): \tpublic native String get_text_from_cpp(String data); \tprivate void callback(String data) {\t\t \t\tfor(ICurlCallbackListener listener:callBackListeners){ \t\t\tlistener.curlCallBack(data); \t\t} \t} } <\/code><\/pre>\n<p>  \u041d\u0443\u0436\u043d\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 AndroidManifest \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442   <\/p>\n<pre><code class=\"xml\">&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;\/&gt; <\/code><\/pre>\n<p>  <\/p>\n<h5>\u0421++ \u0447\u0430\u0441\u0442\u044c<\/h5>\n<p>  \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0443\u0442\u0438\u043b\u0438\u0442\u044b <a href=\"http:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/tooldocs\/windows\/javah.html\">javah<\/a> \u0444\u0430\u0439\u043b <b>com_ifree_ndkNative_Native.h<\/b>  <\/p>\n<pre><code>\/* DO NOT EDIT THIS FILE - it is machine generated *\/ #include &lt;jni.h&gt; \/* Header for class com_ifree_ndkNative_Native *\/  #ifndef _Included_com_ifree_ndkNative_Native #define _Included_com_ifree_ndkNative_Native #ifdef __cplusplus extern &quot;C&quot; { #endif \/*  * Class:     com_ifree_ndkNative_Native  * Method:    get_text_from_cpp  * Signature: (Ljava\/lang\/String;)Ljava\/lang\/String;  *\/ JNIEXPORT jstring JNICALL Java_com_ifree_ndkNative_Native_get_1text_1from_1cpp   (JNIEnv *, jobject, jstring);  #ifdef __cplusplus } #endif #endif  <\/code><\/pre>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (JNICALL Java_com_ifree_ndkNative_Native_get_1text_1from_1cpp) \u0432 <b>ndkNative.cpp<\/b>  <\/p>\n<pre><code>#include &lt;string.h&gt; #include &lt;stdio.h&gt; #include &quot;stddef.h&quot; #include &lt;jni.h&gt; #include &quot;com_ifree_ndkNative_Native.h&quot; #include &quot;curl\/curl.h&quot; #include &quot;curl\/easy.h&quot;  JNIEnv * gEnv; jobject gObj;  void function_callback(jstring str){ \t  jclass cls = gEnv-&gt;GetObjectClass(gObj); \t  jmethodID mid = gEnv-&gt;GetMethodID(cls, &quot;callback&quot;, &quot;(Ljava\/lang\/String;)V&quot;);\/\/\u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 java Native.callback(String data) \t  gEnv-&gt;CallVoidMethod(gObj, mid, str); }  size_t function_pt(void *ptr, size_t size, size_t nmemb, void *stream){ \tfunction_callback(gEnv-&gt;NewStringUTF((char *) ptr)); \tsize_t written = fwrite(ptr, size, nmemb, (FILE*)stream); \t  if(written &lt;= 0) \t  return written * size; }  JNIEXPORT jstring JNICALL Java_com_ifree_ndkNative_Native_get_1text_1from_1cpp   (JNIEnv * env, jobject obj, jstring str) { \tgEnv = env; \tgObj = obj;  \tCURL *curl; \tCURLcode res; \tcurl = curl_easy_init(); \tif(curl) { \t    curl_easy_setopt(curl, CURLOPT_URL, env-&gt;GetStringUTFChars(str, 0)); \t    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, function_pt); \t    res = curl_easy_perform(curl); \t    curl_easy_cleanup(curl);         \/* Check for errors *\/ \t\tif(res != CURLE_OK) \t\t\tfunction_callback(gEnv-&gt;NewStringUTF(curl_easy_strerror(res))); \t  }else{ \t\t  function_callback(gEnv-&gt;NewStringUTF(&quot;error&quot;)); \t  } \t  return env-&gt;NewStringUTF( &quot;ok&quot; ); } <\/code><\/pre>\n<p>  <b>Android.mf<\/b>  <\/p>\n<pre><code>LOCAL_PATH := $(call my-dir)  include $(CLEAR_VARS)  include $(CLEAR_VARS) LOCAL_MODULE:= libcurl LOCAL_SRC_FILES := libcurl.a include $(PREBUILT_STATIC_LIBRARY)  include $(CLEAR_VARS) LOCAL_MODULE    := ndkNative LOCAL_SRC_FILES := ndkNative.cpp LOCAL_STATIC_LIBRARIES := libcurl include $(BUILD_SHARED_LIBRARY) <\/code><\/pre>\n<h4>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a<\/h4>\n<p>  <a href=\"https:\/\/dl.dropboxusercontent.com\/u\/38942741\/ndkNative.zip\"><img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/d00\/7fd\/465\/d007fd465c38f794b4744f8133bad949.png\"\/><\/a><\/p>\n<p>  P.S.: \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u0438\u0434\u043e\u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0435\u0433\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0421++ \u043a\u043b\u0430\u0441\u0441-\u043e\u0431\u0432\u0435\u0440\u0442\u043a\u0443.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/184738\/\"> http:\/\/habrahabr.ru\/post\/184738\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/storage2\/162\/b5c\/6fe\/162b5c6feccc025d10e823820b4b1ac8.png\"\/><\/p>\n<h4>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e<\/h4>\n<p>  \u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441 API \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 C++, \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0432\u043e \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u043c\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043f\u043e\u0434 android.<\/p>\n<p>  Libcurl \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 API \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432 \u0441\u0432\u043e\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b; <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a \u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u0430\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u0430 \u0434\u043b\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 libcurl. libcurl \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 (\u0430\u0434\u0440\u0435\u0441\u0443\u0435\u043c\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e URL) \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c (\u043a\u0430\u043a \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c, \u0442\u0430\u043a \u0438 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u0438\u043c). (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Main_Page\">wikipedia<\/a>)<\/p>\n<p>  \u0414\u043b\u044f iOS \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u0441 \u0441\u0430\u0439\u0442\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u0418 \u0441 iOS \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>  \u041f\u043e\u0434 android \u043c\u043d\u0435 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 google \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430, \u0433\u0434\u0435 \u0431\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u044d\u0442\u043e\u0439 \u043a\u0440\u043e\u0441\u0441-\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435. (\u041c\u043e\u0436\u0435\u0442 \u044f \u043f\u043b\u043e\u0445\u043e \u0438\u0441\u043a\u0430\u043b).<\/p>\n<p>  \u0418 \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f \u043f\u043e\u0434 android \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c <a href=\"http:\/\/curl.haxx.se\">cURL<\/a> \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0447\u0435\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-184738","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/184738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184738"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/184738\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}