2014-10-01 59 views
0

我已经创建了由我希望各国财长将保存到我的远程server.Thanks提前如何将FUNF探针保存到远程服务器?

公共类只使用基本的探头就像wifi和简单location.At数据保存到SD卡的那一刻起funf应用MainActivity扩展活动实现的DataListener {

public static final String PIPELINE_NAME = "default"; 
private FunfManager funfManager; 
private BasicPipeline pipeline; 
private WifiProbe wifiProbe; 
private SimpleLocationProbe locationProbe; 
private CheckBox enabledCheckbox; 
private Button archiveButton, scanNowButton; 
private TextView dataCountView; 
private Handler handler; 
private ServiceConnection funfManagerConn = new ServiceConnection() {  
    @Override 
    public void onServiceConnected(ComponentName name, IBinder service) { 
     funfManager = ((FunfManager.LocalBinder)service).getManager(); 

     Gson gson = funfManager.getGson(); 
     wifiProbe = gson.fromJson(new JsonObject(), WifiProbe.class); 
     locationProbe = gson.fromJson(new JsonObject(), SimpleLocationProbe.class); 
     pipeline = (BasicPipeline) funfManager.getRegisteredPipeline(PIPELINE_NAME); 
     wifiProbe.registerPassiveListener(MainActivity.this); 
     locationProbe.registerPassiveListener(MainActivity.this); 

     // This checkbox enables or disables the pipeline 
     enabledCheckbox.setChecked(pipeline.isEnabled()); 
     enabledCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       if (funfManager != null) { 
        if (isChecked) { 
         funfManager.enablePipeline(PIPELINE_NAME); 
         pipeline = (BasicPipeline) funfManager.getRegisteredPipeline(PIPELINE_NAME); 
        } else { 
         funfManager.disablePipeline(PIPELINE_NAME); 
        } 
       } 
      } 
     }); 

     // Set UI ready to use, by enabling buttons 
     enabledCheckbox.setEnabled(true); 
     archiveButton.setEnabled(true); 

     scanNowButton.setEnabled(true); 

    } 

    @Override 
    public void onServiceDisconnected(ComponentName name) { 
     // TODO Auto-generated method stub 
     funfManager = null; 

    } 



}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

// Forces the pipeline to scan now 
    scanNowButton = (Button) findViewById(R.id.scanNowButton); 
    scanNowButton.setEnabled(false); 
    scanNowButton.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (pipeline.isEnabled()) { 
       // Manually register the pipeline 
       wifiProbe.registerListener(pipeline); 
       locationProbe.registerListener(pipeline); 
      } else { 
       Toast.makeText(getBaseContext(), "Pipeline is not enabled.", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 

    // Displays the count of rows in the data 
    dataCountView = (TextView) findViewById(R.id.dataCountText); 

    // Used to make interface changes on main thread 
    handler = new Handler(); 

    enabledCheckbox = (CheckBox) findViewById(R.id.enabledCheckbox); 
    enabledCheckbox.setEnabled(false); 

    // Runs an archive if pipeline is enabled 
    archiveButton = (Button) findViewById(R.id.archiveButton); 
    archiveButton.setEnabled(false); 
    archiveButton.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (pipeline.isEnabled()) { 
       pipeline.onRun(BasicPipeline.ACTION_ARCHIVE, null); 

       // Wait 1 second for archive to finish, then refresh the UI 
       // (Note: this is kind of a hack since archiving is seamless and there are no messages when it occurs) 
       handler.postDelayed(new Runnable() { 
        @Override 
        public void run() { 
         Toast.makeText(getBaseContext(), "Archived!", Toast.LENGTH_SHORT).show(); 
         updateScanCount(); 
        } 
       }, 1000L); 
      } else { 
       Toast.makeText(getBaseContext(), "Pipeline is not enabled.", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 

    // Bind to the service, to create the connection with FunfManager 
    bindService(new Intent(this, FunfManager.class), funfManagerConn, BIND_AUTO_CREATE); 
} 

@Override 
public void onDataCompleted(IJsonObject probeConfig, JsonElement checkpoint) { 
    updateScanCount(); 

    // Re-register to keep listening after probe completes. 
    wifiProbe.registerPassiveListener(this); 
    locationProbe.registerPassiveListener(this); 
} 


@Override 
public void onDataReceived(IJsonObject arg0, IJsonObject arg1) { 
    // TODO Auto-generated method stub 

} 
private static final String TOTAL_COUNT_SQL = "SELECT count(*) FROM " + NameValueDatabaseHelper.DATA_TABLE.name; 
/** 
* Queries the database of the pipeline to determine how many rows of data we have recorded so far. 
*/ 
private void updateScanCount() { 
    // Query the pipeline db for the count of rows in the data table 
    SQLiteDatabase db = pipeline.getDb(); 
    Cursor mcursor = db.rawQuery(TOTAL_COUNT_SQL, null); 
    mcursor.moveToFirst(); 
    final int count = mcursor.getInt(0); 
    // Update interface on main thread 
    runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      dataCountView.setText("Data Count: " + count); 
     } 
    }); 
} 

}

回答

0

将数据发送到远程服务器,首先你需要配置的strings.xml

像下面的文件。

"archive": { 
       "@schedule": {"interval": 60} 
      }, 
"upload": { 
        "url": \"http://example.com/test/android_data_receiver.php\", 
        "@schedule": {"interval": 60} 
      } 

将数据发送到服务器每隔1分钟,还要确保你已经添加

权限访问远程服务器到Android清单文件

规范允许的权限

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

完成上述步骤后,请在您的域中创建一个服务器文件,对于

测试目的我在下面创建了一个文件。你可以根据你的需要修改文件。

<?php 

    $target_path = "uploads/"; 
    $target_path = $target_path . basename($_FILES['uploadedfile']['name']); 

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
     echo "The file ". basename($_FILES['uploadedfile']['name'])." has been uploaded"; 
    } 
    else { 
     echo "There was an error uploading the file, please try again!"; 
    } 
?> 
0

您需要在服务器数据库和一些后台功能将数据添加到您的远程数据库。后端功能应该是服务器,你可以从你的Android应用程序通过的HttpRequest等称之为..阅读关于REST API的

+0

如果我创建数据库我怎么知道我的领域,并再次在那里把后端功能 – walters 2014-10-01 14:11:08

+0

你什么意思,你怎么会知道你的领域?例如,您应该编写PHP函数来调用它,以打开数据库,并在数据中插入一行。然后从android发送HTTPRequest(或POST),并使用应用程序中的数据调用该函数。 PHP函数获取您发送的数据,并在一切正常时返回响应。 – 2014-10-01 16:29:51

+0

Hi @walters Hi,你有答案吗?如果没有请平安我,我可以帮助你。 – vipin 2014-10-22 12:18:40

相关问题