forked from FlyingRadish/Leamonax
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/org/houxg/leamonax/utils/ShareUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.houxg.leamonax.utils; | ||
|
||
import android.content.Intent; | ||
import android.text.TextUtils; | ||
|
||
import static android.content.Intent.ACTION_SEND; | ||
import static android.content.Intent.EXTRA_SUBJECT; | ||
import static android.content.Intent.EXTRA_TEXT; | ||
|
||
|
||
/** | ||
* Utilities for creating a share intent | ||
*/ | ||
public class ShareUtils { | ||
|
||
/** | ||
* Create intent with subject and body | ||
* | ||
* @param subject | ||
* @param body | ||
* @return intent | ||
*/ | ||
public static Intent create(final CharSequence subject, | ||
final CharSequence body) { | ||
Intent intent = new Intent(ACTION_SEND); | ||
intent.setType("text/plain"); | ||
if (!TextUtils.isEmpty(subject)) | ||
intent.putExtra(EXTRA_SUBJECT, subject); | ||
intent.putExtra(EXTRA_TEXT, body); | ||
return intent; | ||
} | ||
|
||
/** | ||
* Get body from intent | ||
* | ||
* @param intent | ||
* @return body | ||
*/ | ||
public static String getBody(final Intent intent) { | ||
return intent != null ? intent.getStringExtra(EXTRA_TEXT) : null; | ||
} | ||
|
||
/** | ||
* Get subject from intent | ||
* | ||
* @param intent | ||
* @return subject | ||
*/ | ||
public static String getSubject(final Intent intent) { | ||
return intent != null ? intent.getStringExtra(EXTRA_SUBJECT) : null; | ||
} | ||
} |