예제 #1
0
    @Override
    public DownloadStreamTask(Context _c) {
      mContext = new WeakReference<Context>(_c);
      // dialog = new ProgressDialog(myact.this);

      text1 = (TextView) findViewById(R.id.textView1);

      Button cancelbtn = (Button) findViewById(R.id.ButtonCancel);
      cancelbtn.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              // Do something in response to button click
              cancel(true);
            }
          });

      cancelbtn.setEnabled(true);
    }
예제 #2
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.receiver);

    final Button cancelbtn = (Button) findViewById(R.id.ButtonCancel);
    // cancelbtn.setEnabled(false);
    cancelbtn.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // streamtask.cancel(true);
            finish();
          }
        });

    try {
      Intent intent = getIntent();
      String action = intent.getAction();
      String type = intent.getType();

      if ((!(Intent.ACTION_SEND.equals(action))) || (type == null)) {
        throw new RuntimeException("Unknown intent action or type");
      }

      if (!("text/plain".equals(type))) {
        throw new RuntimeException("Type is not text/plain");
      }

      String extra = intent.getStringExtra(Intent.EXTRA_TEXT);
      if (extra == null) {
        throw new RuntimeException("Cannot get shared text");
      }

      final DownloadStreamTask streamtask = new DownloadStreamTask(this);

      //	Once created, a task is executed very simply:
      streamtask.execute(extra);

    } catch (Exception e) {
      Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
    }
  }