0

我在 Unity 工作,想获得文件选择活动的结果。由于我无法从 Unity 本身启动活动,因此我创建了一个名为 EclipseIntegration 的“中间”静态类:

package com.Unity3D.EclipseIntegration;

public class EclipseIntegration {

    public static String selectedPath = "really ";

      public static void Launch(Activity activity) {
        Intent target = new Intent(activity, MyActivity.class);
        activity.startActivity(target); 
      }
}

activity 是 Unity 当前正在运行的 Activity。

MyActivity 旨在启动真正的活动,因为我需要从 Activity 继承的东西来获取 onActivityResult 事件:

package com.Unity3D.EclipseIntegration;

public class MyActivity extends Activity{

        @Override
        public void onCreate(Bundle savedInstanceState) {         
           super.onCreate(savedInstanceState);    
           Launch();
       }

      public void Launch() {
        Intent target = FileUtils.createGetContentIntent();
        Intent intent = Intent.createChooser(target, "Select a movie");
        startActivityForResult(intent); 
      }

      @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case 128:   
                if (resultCode == RESULT_OK) {  
                    final Uri uri = data.getData();
                    File file = FileUtils.getFile(uri);
                    EclipseIntegration.selectedPath = file.getAbsolutePath();
                }
                else EclipseIntegration.selectedPath = "";
                finish();
        }
    }     
}

但什么也没发生。如果我像这样直接在静态类中启动最终活动:activity.startActivity(intent); 它虽然有效,所以我想我在设置 MyActivity 时犯了一些错误?尽管现在尝试了 2 天,但我还是找不到它,所以任何朝着正确方向轻推都会非常感激 :)

谢谢,基里里

4

1 回答 1

0

试试这个方法

public void Launch() {
            Intent target = FileUtils.createGetContentIntent();
            Intent intent = Intent.createChooser(target, "Select a movie");
            startActivityForResult(intent,128); 
          }
于 2013-09-13T09:57:36.667 回答