2014-02-20 63 views
2

我正在開發一款應該能夠在設備之間傳輸簡單數據的應用程序。使用我的應用程序從html文件中讀取數據的簡單方法?

所以第一步是從我的應用程序發送的設備1的一些數據到設備2.我用下面的代碼:

Button btnShare = (Button)findViewById(R.id.btnShare); 
    btnShare.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent sendIntent = new Intent(); 
      sendIntent.setAction(Intent.ACTION_SEND); 
      sendIntent.setType("text/plain"); 
      sendIntent.putExtra(Intent.EXTRA_TEXT, "Name:"+oldName+",Surname:"+oldName); 
      startActivity(sendIntent); 

     } 
    }); 

按鈕後點擊Android的份額菜單出現,我選擇藍牙選項。我用它將數據發送到設備2,並以擴展名「.html」作爲文件。

現在我想打開該文件,並使用存儲在我的應用程序在第二個設備上的數據。 我點擊我的藍牙文件夾中的文件,並從菜單中選擇我的應用程序,並將建議的應用程序與html文件一起使用。

我的應用程序在第二臺設備上啓動,但我無法從文件中獲取數據。

什麼是從該文件與我的應用程序獲取數據最簡單的方法? 我應該使用ACTION_VIEW嗎?

回答

1

在被打開後,您需要通過Intent對象

Intent intent = getIntent(); 
    Uri uri = intent.getData(); 
    String filename = null; 
    if (uri!=null) 
     filename = uri.getPath(); 
+0

獲取數據的活動謝謝我做了一個進步。你能告訴我如何從上面的代碼中使用putExtra檢索信息嗎? – dafilipaj

相關問題