Exemplo n.º 1
1
    protected void doDownload(String url, String filename) {
      // String url = "url you want to download";
      DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
      request.setDescription(filename);
      request.setTitle("Stream Downloader");

      // in order for this if to run, you must use the android 3.2 to compile your app
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(
            DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
      }
      request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);

      // get download service and enqueue file
      DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
      manager.enqueue(request);
    }
Exemplo n.º 2
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   Intent intent = getIntent();
   Uri uri = intent.getData();
   if (uri != null) {
     MainActivity.addLink(this, uri.toString());
     Uri newUri = Uri.parse("view-source:" + uri.toString());
     startChrome(newUri);
   }
   if (Intent.ACTION_SEND.equals(intent.getAction())) {
     Bundle extras = intent.getExtras();
     if (extras != null) {
       String text = extras.getString(Intent.EXTRA_TEXT);
       Pattern pattern = Pattern.compile(URL_PATTERN);
       if (text != null) {
         Matcher m = pattern.matcher(text);
         if (m.find()) {
           String url = m.group(1);
           MainActivity.addLink(this, url);
           Uri newUri = Uri.parse("view-source:" + url);
           startChrome(newUri);
         }
       }
     }
   }
   this.finish();
 }
Exemplo n.º 3
0
 void copyIntent() {
   ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
   Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
   ClipData clip = ClipData.newIntent("intent", intent);
   cm.setPrimaryClip(clip);
   Toast.makeText(this, "Intent Copied", 0).show();
 }
Exemplo n.º 4
0
 public void startChrome(Uri uri) {
   Intent it = new Intent(Intent.ACTION_VIEW);
   it.setData(uri);
   it.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
   it.setClassName("com.android.chrome", "com.google.android.apps.chrome.Main");
   try {
     startActivity(it);
   } catch (ActivityNotFoundException ex) {
     Intent intent =
         new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?id=com.android.chrome"));
     startActivity(intent);
   }
 }
Exemplo n.º 5
0
 public static Contribution fromCursor(Cursor cursor) {
   // Hardcoding column positions!
   Contribution c = new Contribution();
   c.contentUri = ContributionsContentProvider.uriForId(cursor.getInt(0));
   c.filename = cursor.getString(1);
   c.localUri = TextUtils.isEmpty(cursor.getString(2)) ? null : Uri.parse(cursor.getString(2));
   c.imageUrl = cursor.getString(3);
   c.timestamp = cursor.getLong(4) == 0 ? null : new Date(cursor.getLong(4));
   c.state = cursor.getInt(5);
   c.dataLength = cursor.getLong(6);
   c.dateUploaded = cursor.getLong(7) == 0 ? null : new Date(cursor.getLong(7));
   c.transferred = cursor.getLong(8);
   c.source = cursor.getString(9);
   c.description = cursor.getString(10);
   c.creator = cursor.getString(11);
   c.isMultiple = cursor.getInt(12) == 1;
   return c;
 }
Exemplo n.º 6
0
 @Override
 public void onClick(View v) {
   // TODO Auto-generated method stub
   Intent intent;
   String parentPN; // 蹂댄샇���꾪솕踰덊샇
   /** 媛�踰꾪듉蹂꾨줈 �댁빞���쇱쓣 梨꾩썙�k뒗�� */
   switch (v.getId()) {
     case R.id.mystatbtn:
       intent = new Intent(Menus.this, Mystat.class);
       startActivity(intent);
       break;
     case R.id.noticebtn:
       intent = new Intent(Menus.this, Notice.class);
       startActivity(intent);
       break;
     case R.id.requestbtn:
       intent = new Intent(Menus.this, RequestTalk.class);
       startActivity(intent);
       break;
     case R.id.hospitalinfobtn:
       intent = new Intent(Menus.this, Hospitalinfo.class);
       startActivity(intent);
       break;
     case R.id.qrreadbtn:
       intent = new Intent(Menus.this, QRread.class);
       startActivity(intent);
       break;
     case R.id.parentcallbtn:
       parentPN = "01193699621"; // 蹂댄샇���꾪솕踰덊샇 DB�먯꽌 媛�졇��빞 ��
       intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + parentPN));
       startActivity(intent);
       break;
     case R.id.emergencybtn:
       // 蹂묒썝��湲닿툒肄�
       ((Button) findViewById(R.id.emergencybtn)).setBackgroundColor(Color.GREEN);
       ((Button) findViewById(R.id.emergencybtn)).setText("�좉퀬 �꾨즺");
       break;
   }
 }
Exemplo n.º 7
0
        public void onClick(View v) {
          ContentResolver cr = getContentResolver();
          switch (v.getId()) {
              // 전부 읽기
            case R.id.readall:
              Cursor cursor = cr.query(Uri.parse(WORDURI), null, null, null, null);

              String Result = "";
              while (cursor.moveToNext()) {
                String eng = cursor.getString(0);
                String han = cursor.getString(1);
                Result += (eng + " = " + han + "\n");
              }

              if (Result.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result);
              }
              cursor.close();
              break;
              // 하나만 읽기
            case R.id.readone:
              Cursor cursor2 = cr.query(Uri.parse(WORDURI + "/boy"), null, null, null, null);

              String Result2 = "";
              if (cursor2.moveToFirst()) {
                String eng = cursor2.getString(0);
                String han = cursor2.getString(1);
                Result2 += (eng + " = " + han + "\n");
              }

              if (Result2.length() == 0) {
                mText.setText("Empyt Set");
              } else {
                mText.setText(Result2);
              }
              cursor2.close();
              break;
              // 삽입
            case R.id.insert:
              ContentValues row = new ContentValues();
              row.put("eng", "school");
              row.put("han", "학교");

              cr.insert(Uri.parse(WORDURI), row);
              mText.setText("Insert Success");
              break;
              // 삭제
            case R.id.delete:
              cr.delete(Uri.parse(WORDURI), null, null);
              mText.setText("Delete Success");
              break;
              // 수정
            case R.id.update:
              ContentValues row2 = new ContentValues();
              row2.put("han", "핵교");
              cr.update(Uri.parse(WORDURI + "/school"), row2, null, null);
              mText.setText("Update Success");
              break;
          }
        }
    protected Boolean doInBackground(ArrayList... params) {
      download_photos.this.runOnUiThread(
          new Runnable() {
            public void run() {
              mtext.setText(
                  getText(R.string.download_textview_message_1) + " " + path.toString() + ". ");
            }
          });

      if (resume_file.exists()) {
        initial_value = readProgress()[0];
      } else {
        initial_value = 1;
      }

      for (int i = initial_value - 1; i < links.size(); i++) {
        // asynctask expects more than one ArrayList<String> item, but we are sending only one,
        // which is params[0]
        Uri imageuri = Uri.parse(params[0].get(i).toString());
        URL imageurl = null;
        HttpURLConnection connection = null;
        total_files_to_download = links.size();
        completed_downloads = i + 1;
        try {
          imageurl = new URL(params[0].get(i).toString());
          connection = (HttpURLConnection) imageurl.openConnection();
          connection.connect();
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        // extracts the real file name of the photo from url
        path_segments = imageuri.getPathSegments();
        int total_segments = path_segments.size();
        file_name = path_segments.get(total_segments - 1);

        path.mkdirs();

        // if(i==0)
        //	first_image = path.toString() + "/" + file_name;

        InputStream input;
        OutputStream output;
        try {
          input = new BufferedInputStream(imageurl.openStream());
          fully_qualified_file_name = new File(path, file_name);
          output = new BufferedOutputStream(new FileOutputStream(fully_qualified_file_name));
          byte data[] = new byte[1024];
          int count;
          while ((count = input.read(data)) != -1) {
            output.write(data, 0, count);
          }
          output.flush();
          output.close();
          input.close();
          connection.disconnect();

          new folder_scanner(getApplicationContext(), fully_qualified_file_name);

          publishProgress(completed_downloads, total_files_to_download);
          if (this.isCancelled()) {
            writeProgress(completed_downloads, total_files_to_download);
            break;
          }

        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        // creates required folders and subfolders if they do not exist already
        // boolean success = path.mkdirs();

        // makes request to download photos
        // DownloadManager.Request request = new DownloadManager.Request(imageuri);

        // set path for downloads
        // request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,sub_path);

        // request.setDescription("Downloaded using Facebook Album Downloader");

        // DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);

        // download is enqueue in download list. it returns unique id for each download
        // download_id = dm.enqueue(request);

      }
      // returns the unique id. we are not using this id
      return true;
    }