Astro文件浏览器和Intents

时间:2011-07-13 17:18:18

标签: android android-intent intentfilter astro

当我选择某种文件类型时,我能够让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);
....
}
}

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

1 个答案:

答案 0 :(得分:1)

如果我找到你,你只需在onCreate方法中拨打getIntent即可。

要获取意图包,请在意图上调用getExtras