0

enter image description here this is the Exception!

These are codes!This is not certain happen,in service,log display of the devices are samsung,and system is greater than android 6.0. I don't know the reasons,Could you help me,Thanks guys

public static void share(Context context, String packageName, String path, String content) {

    Intent intent = new Intent(Intent.ACTION_SEND);
    if (TextUtils.isEmpty(path)) {
        intent.setType("text/plain"); // 
    } else {
        File file = new File(path);
        if (file.exists() && file.isFile()) {
            intent.setType("image/*");
            Uri uri = Uri.fromFile(file);
            intent.putExtra(Intent.EXTRA_STREAM, uri);
        }
    }

    intent.putExtra(Intent.EXTRA_TEXT, content);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (!TextUtils.isEmpty(packageName)) {
        intent.setPackage(packageName);
        context.startActivity(intent);
        return;
    }
    context.startActivity(Intent.createChooser(intent, ""));
}
Liang
  • 1

2 Answers2

0

The problem is that the OS didn't find any activities which can handle this ACTION_SEND. Surround this kind of code with a try/catch, since you can not be sure if there exists an activity that can handle your intent. And try to install at least one app that can handle the ACTION_SEND, then try again, and see if it works for you

Shishupal Shakya
  • 1,632
  • 2
  • 18
  • 41
  • This is user feedback to us,In our developing,we didn't appear this question,and i try again don't appear this question too.Beause facebook ,it is a button,when check facebook isn't exist,we set it Visible.GONE. So I think shouldn't appear this question – Liang Sep 06 '16 at 02:45
0

Before you calling startActivity(intent), you should use intent.resolveActivity(getPackageManager()) != null) to check if there is an activity could resolve this intent.

Dennis Lee
  • 80
  • 1
  • 1
  • 9
  • Before startActivity(intent) ,I checked the facebook if there exists. If it isn't exist,the button of facebook can't be visible – Liang Sep 06 '16 at 03:00