Skip to content

Commit

Permalink
catch exceptions while open links or send emails
Browse files Browse the repository at this point in the history
  • Loading branch information
zfdang committed May 14, 2016
1 parent 3551543 commit 44ebc25
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.zfdang.zsmth_android.helpers;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.widget.Toast;

import com.klinker.android.link_builder.Link;
Expand All @@ -18,27 +20,34 @@
* Created by zfdang on 2016-5-14.
*/
public class ActivityUtils {
private static final String TAG = "ActivityUtils";

public static void openLink(String link, Activity activity) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
activity.startActivity(browserIntent);
try {
activity.startActivity(browserIntent);
} catch(ActivityNotFoundException e) {
Toast.makeText(activity, "链接打开错误:" + e.toString(), Toast.LENGTH_LONG).show();
}
}


public static void sendEmail(String link, Activity activity) {
/* Create the Intent */
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

/* Fill it with Data */
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{link});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "来自zSMTH的邮件");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, " \n \n \n \n--\n来自zSMTH的邮件\n");

/* Send it off to the Activity-Chooser */
activity.startActivity(Intent.createChooser(emailIntent, "发邮件..."));
try {
activity.startActivity(Intent.createChooser(emailIntent, "发邮件..."));
} catch(ActivityNotFoundException e) {
Toast.makeText(activity, "链接打开错误:" + e.toString(), Toast.LENGTH_LONG).show();
}
}


// this will be called in PostRecyclerViewAdapter & MailContentActivity
public static List<Link> getPostSupportedLinks(final Activity activity) {
List<Link> links = new ArrayList<>();
Expand Down

0 comments on commit 44ebc25

Please sign in to comment.