【问题标题】:Astro file browser and IntentsAstro 文件浏览器和 Intents
【发布时间】:2011-07-13 17:18:17
【问题描述】:

当我选择某种文件类型时,我能够让 Astro 启动我的活动。但是,当我的活动开始时,我不知道如何获取意图!

public class Viewer extends ListActivity{
....
// Flag if receiver is registered 
private boolean mReceiversRegistered = false;

// I think this is the broadcast you need for something like an incoming call
private String INCOMING_CALL_ACTION = "android.intent.action.VIEW";
// Define a handler and a broadcast receiver
private final Handler mHandler = new Handler();

private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    // Handle reciever
    String mAction = intent.getAction();
    Toast.makeText(context,"Found with passed context", Toast.LENGTH_LONG).show();
    Toast.makeText(BallLidarViewer.this, "Found with my context", toast.LENGTH_LONG).show();
    System.out.print("FOUND");
    Log.d("FOUND","FOUND");
    if(mAction.equals(INCOMING_CALL_ACTION)) {
      // Do your thing   

    }
  }
};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
....
}
}

当我的活动开始时,我的任何测试输出代码都无法运行。我究竟做错了什么?谢谢!

【问题讨论】:

    标签: android android-intent intentfilter astro


    【解决方案1】:

    如果我没听错,您可以在 onCreate 方法中简单地调用 getIntent

    要获取 Intent 的捆绑包,请在 Intent 上调用 getExtras

    【讨论】:

    • 我也想过这个问题,但我不知道如何从中获取文件路径(这就是我想要的)。有没有办法查看 Intent 中包含的数据?
    猜你喜欢
    • 1970-01-01
    • 2020-12-31
    • 2012-12-22
    • 2019-10-10
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    相关资源
    最近更新 更多