我在Unity工作,希望得到文件拣选活动的结果。由于我无法从Unity本身启动活动,因此我创建了一个名为EclipseIntegration的“intermediant”静态类:
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);
}
}
活动是当前正在运行的活动。
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(意向);虽然它有效,所以我想在设置MyActivity时我犯了一些错误?尽管尝试了2天我现在找不到它,所以任何朝着正确方向的推动都会非常感激:)
谢谢, kiriri
答案 0 :(得分:0)
试试这种方式
public void Launch() {
Intent target = FileUtils.createGetContentIntent();
Intent intent = Intent.createChooser(target, "Select a movie");
startActivityForResult(intent,128);
}