Android Open Source - GreenerGasPedal Share Util






From Project

Back to project page GreenerGasPedal.

License

The source code is released under:

GNU General Public License

If you think the Android project GreenerGasPedal listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package name.nanek.greenerpedal.activity.support;
//from   ww w . ja  va2s .  c  o  m
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore.Images;

public class ShareUtil {
  
  private static final String SHARE_TYPE = "image/jpeg";

  private static final String FILE_URI_PREFIX = "file://";
  
  public static void share(final Activity activity, final String path, final int requestCode) {
    final Intent share = new Intent();

    share.putExtra(Intent.EXTRA_STREAM,  Uri.parse(FILE_URI_PREFIX + path));

    share(activity, share, requestCode);
  }
  
  public static void share(final Activity activity, final Bitmap screenshot, final int requestCode) {
    final Intent share = new Intent();

    String path = Images.Media.insertImage(activity.getContentResolver(), screenshot, "Greener Pedal", null);
    Uri screenshotUri = Uri.parse(path);
    share.putExtra(Intent.EXTRA_STREAM, screenshotUri);

    share(activity, share, requestCode);
  }
  
  private static void share(final Activity activity, final Intent share, final int requestCode) {
    
    share.setAction(Intent.ACTION_SEND);
    share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    share.setType(SHARE_TYPE);

    share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    String story = "My driving with Greener Pedal";

    share.putExtra(Intent.EXTRA_TEXT, story);
    share.putExtra("sms_body", story);
    share.putExtra(Intent.EXTRA_TITLE, story);
    share.putExtra(Intent.EXTRA_SUBJECT, story);
    activity.startActivityForResult(Intent.createChooser(share, "Choose a way to share:"), requestCode);
  }

}




Java Source Code List

name.nanek.greenerpedal.GreenerPedalApp.java
name.nanek.greenerpedal.activity.DisplayReadingsActivity.java
name.nanek.greenerpedal.activity.EditPrefsActivity.java
name.nanek.greenerpedal.activity.GraphAndShareActivity.java
name.nanek.greenerpedal.activity.support.APISafeKeyguardHider.java
name.nanek.greenerpedal.activity.support.BitmapUtil.java
name.nanek.greenerpedal.activity.support.LogLine.java
name.nanek.greenerpedal.activity.support.LowPassFilter.java
name.nanek.greenerpedal.activity.support.MessageOnlyFormatter.java
name.nanek.greenerpedal.activity.support.Prefs.java
name.nanek.greenerpedal.activity.support.ScreenLock.java
name.nanek.greenerpedal.activity.support.Sensors.java
name.nanek.greenerpedal.activity.support.ShareUtil.java
name.nanek.greenerpedal.activity.support.Trigger.java
name.nanek.greenerpedal.activity.support.TriggersResult.java
name.nanek.greenerpedal.activity.support.Views.java
name.nanek.greenerpedal.db.model.Reading.java
name.nanek.greenerpedal.db.model.dao.DataHelper.java
name.nanek.greenerpedal.db.model.dao.ReadingDao.java
name.nanek.greenerpedal.db.model.dao.support.DateUtil.java
name.nanek.greenerpedal.db.model.dao.support.DbUtil.java