Showing posts with label Intent. Show all posts
Showing posts with label Intent. Show all posts

Saturday, 6 April 2013

Android Intents How to pick a file with an Intent?


The code allows any application to call AndExplorer intent to pick a file on phone or SDCard. AndExplorer is free and available at: http://www.lysesoft.com/products/andexplorer/index.html 


int PICK_REQUEST_CODE = 0;
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
Uri startDir = Uri.fromFile(new File("/sdcard"));
// Files and directories !
intent.setDataAndType(startDir, "vnd.android.cursor.dir/lysesoft.andexplorer.file");
// Title
intent.putExtra("explorer_title", "Select a file");
// Optional colors
intent.putExtra("browser_title_background_color", "440000AA");
intent.putExtra("browser_title_foreground_color", "FFFFFFFF");
intent.putExtra("browser_list_background_color", "00000066");
// Optional font scale
intent.putExtra("browser_list_fontscale", "120%");
// Optional 0=simple list, 1 = list with filename and size, 2 = list with filename, size and date.
intent.putExtra("browser_list_layout", "2");
startActivityForResult(intent, PICK_REQUEST_CODE);

...

protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
   if (requestCode == PICK_REQUEST_CODE)
   {
   if (resultCode == RESULT_OK)
   {
      Uri uri = intent.getData();
      String type = intent.getType();
      LogHelper.i(TAG,"Pick completed: "+ uri + " "+type);
      if (uri != null)
      {
         String path = uri.toString();
         if (path.toLowerCase().startsWith("file://"))
         {
            // Selected file/directory path is below
            path = (new File(URI.create(path))).getAbsolutePath();
         }

      }
   }
   else LogHelper.i(TAG,"Back from pick with cancel status");
   }
}

Android SMS How to send an MMS via Intents?


Send a picture via mms. 

          Uri mmsUri = Uri.parse("content://media/external/images/media/1");
          Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra("sms_body", "Hi how are you");
          intent.putExtra(Intent.EXTRA_STREAM, mmsUri);
          intent.setType("image/png");
          startActivity(intent);

Friday, 5 April 2013

Sending E- Mails Using Intent in Android



Before Proceeding to deal with Sending Emails in Android. Let us see first,

          What is Intent?

               Intents are asynchronous messages which help us to activate the Components such as Activities,  

                    Services, Board cast Receivers.
               The Core Components of the Application are invoked by Intents.
               In other words Intent is a horde of Information which contains the Action, Data’s involved in the 

                  Action, and the Category of the Component.

        Use Intents, as shown below, write the following code in the button click event, if you want to send a mail to 

        a user, when the user hits Email Button.

         // Creating a Object for the Class Intent
          Intent sendIntent;
        // Since we want to send ,we are using ACTION_SEND


          sendIntent = new Intent(Intent.ACTION_SEND);
          sendIntent.setType("application/octet-stream");
          sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {"san123@gmail.com"});
          sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Test");
          sendIntent.putExtra(Intent.EXTRA_TEXT, "Hy Testing");
          sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
          sendIntent.setType("image/jpeg");
          startActivity(Intent.createChooser(sendIntent, "Send Mail"));


Download files using Intent



private static final int DOWNLOAD_FILES_REQUEST = 1;

Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_PICK);

          // FTP URL (Starts with ftp://, sftp:// or ftps:// followed by 
             hostname and port).
          Uri ftpUri = Uri.parse("ftp://yourftpserver.com");
          intent.setDataAndType(ftpUri,
                                              "vnd.android.cursor.dir/lysesoft.andftp.uri");


// FTP credentials (optional)
       
      intent.putExtra("ftp_username", "anonymous");
                      intent.putExtra("ftp_password", "something@somewhere.com");
           //intent.putExtra("ftp_keyfile", "/sdcard/dsakey.txt");
           //intent.putExtra("ftp_keypass", "optionalkeypassword");
           intent.putExtra("ftp_pasv", "true");

           //intent.putExtra("ftp_resume", "true");
           //intent.putExtra("ftp_encoding", "UTF8");
           
           // Download
           intent.putExtra("command_type", "download");

           // Activity title

           intent.putExtra("progress_title", "Downloading files ...");
           
           // Remote files to download.
           intent.putExtra("remote_file1", "/remotefolder/subfolder/file1.zip");
           intent.putExtra("remote_file2", "/remotefolder/subfolder/file2.zip");
                     // Target local folder where files will be downloaded.
                      intent.putExtra("local_folder", "/sdcard/localfolder"); 

           startActivityForResult(intent, DOWNLOAD_FILES_REQUEST);



Disqus for Android