1 Reply Latest reply on Jul 26, 2016 11:39 PM by VectorP

    Any way to handle Android App Sharing

    greydarrah

      On Android, many apps can share info with each other.  An example would be to find any specific product in the Amazon app, scroll down the screen just past the "Add to Cart" button and you'll see a "Share" button.  Click it and a number of apps pop up that you can share that Amazon item to/with.  To get an Android app to be on that list of Share apps, you have to add some stuff to your Android Manifest file like:

       

      <activity android:name=".ui.MyActivity" >
         
      <intent-filter>
             
      <action android:name="android.intent.action.SEND" />
             
      <category android:name="android.intent.category.DEFAULT" />
             
      <data android:mimeType="image/*" />
         
      </intent-filter>
         
      <intent-filter>
             
      <action android:name="android.intent.action.SEND" />
             
      <category android:name="android.intent.category.DEFAULT" />
             
      <data android:mimeType="text/plain" />
         
      </intent-filter>
      </activity>

       

       

      Then you create a function in java to handle the shared data like:

       

      void onCreate (Bundle savedInstanceState) {
         
      ...
         
      // Get intent, action and MIME type
         
      Intent intent = getIntent();
         
      String action = intent.getAction();
         
      String type = intent.getType();

         
      if (Intent.ACTION_SEND.equals(action) && type != null) {
             
      if ("text/plain".equals(type)) {
                  handleSendText
      (intent); // Handle text being sent
             
      } else if (type.startsWith("image/")) {
                  handleSendImage
      (intent); // Handle single image being sent
             
      }
         
      } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
             
      if (type.startsWith("image/")) {
                  handleSendMultipleImages
      (intent); // Handle multiple images being sent
             
      }
         
      } else {
             
      // Handle other intents, such as being started from the home screen
         
      }
         
      ...
      }

      void handleSendText(Intent intent) {
         
      String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
         
      if (sharedText != null) {
             
      // Update UI to reflect text being shared
         
      }
      }

      void handleSendImage(Intent intent) {
         
      Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
         
      if (imageUri != null) {
             
      // Update UI to reflect image being shared
         
      }
      }

      void handleSendMultipleImages(Intent intent) {
         
      ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
         
      if (imageUris != null) {
             
      // Update UI to reflect multiple images being shared
         
      }
      }

       

       

       

      Since in PhoneGap (to my knowledge) I don't actually have access to my Manifest file or some other file for the java code (like MainActivity.java), does anyone know if/how this can be done in a PhoneGap build for an Android app?  If it matters, I'm using AppPresser to prepare my app for submission (from my WordPress site) to PhoneGapp.

       

      Thanks for your help,

      Grey Darrah