2016-08-16 7 views
0

私のAndroidアプリケーションにはボタンウィジェットがあります。ここには、他の必要なテキストとは別にactivity_main.xmlというファイルがあります。他の機能とは別にファイルMainActivity.javaテキストファイルを選択してAndroidプラットフォームで読む

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Numbers" 
    android:id="@+id/btnBrowse" 
    android:onClick="clickButtonBrowse" 
/> 

、私は次のように書いた:

protected void clickButtonBrowse() { 
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.addCategory(Intent.CATEGORY_OPENABLE); 
    intent.setType("text/plain"); 
    startActivity(intent, FILE_REQUEST_CODE); 
} 

私の考えは、ファイルブラウザを開き、ファイルを選択することです。私はこの質問on selecting a fileの助けを取った。

は、今私は、次の見当がつかない:

  1. 私はそれを読むことができるように、意図からファイル名を取得する方法。
  2. FILE_REQUEST_CODEはどのように定義されていますか?許容値は何ですか?

お手伝いできますか?

答えて

0
You need to startActivityForResult not startActivity, as in the example you were using. Then you can: 

public synchronized void onActivityResult(final int requestCode, 
     int resultCode, final Intent data) { 

    if (resultCode == Activity.RESULT_OK) { 
     String filePath = data.getStringExtra(FileDialog.RESULT_PATH); 
    } 
} 
+0

ここで、FileDialogは何ですか? – Indian

+0

これは、ファイルをブラウズするために使用しているアクティビティです。あなたが投稿したリンクの詳細を参照してください。ファイルを取得する方法を説明します。あなたがそのクラスのあなたのコピーの名前を何であれ、FileDialiog – usajnf

関連する問題