Java 尝试使用意图共享文本时出现异常

Java 尝试使用意图共享文本时出现异常,java,android,android-intent,Java,Android,Android Intent,我有一个按摩,我希望用户与其他应用程序共享,因此我执行以下操作: String shareBody = "content"; Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); startActi

我有一个按摩,我希望用户与其他应用程序共享,因此我执行以下操作:

String shareBody = "content";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "title"));
问题是我从系统中得到一个异常,我无法找出我做错了什么:

The Google Play services resources were not found. Check your project 

configuration to ensure that the resources are included.
09-24 14:25:53.618 24079-24079/? E/MotionRecognitionManager: mSContextService = android.hardware.scontext.ISContextService$Stub$Proxy@e2ecc0
09-24 14:25:53.618 24079-24079/? E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@1417df9
09-24 14:25:53.618 24079-24079/? E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@1417df9
09-24 14:25:53.868 24079-24177/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #5
                                                   Process: android:ui, PID: 24079
                                                   java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                       at android.os.AsyncTask$3.done(AsyncTask.java:309)
                                                       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                       at java.lang.Thread.run(Thread.java:818)
                                                    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.drawable.Drawable.getIntrinsicWidth()' on a null object reference
                                                       at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3062)
                                                       at android.app.ApplicationPackageManager.getThemeIconWithBG(ApplicationPackageManager.java:3037)
                                                       at android.app.ApplicationPackageManager.getDrawableForIconTray(ApplicationPackageManager.java:2933)
                                                       at com.android.internal.app.ResolverActivity.loadIconForResolveInfo(ResolverActivity.java:797)
                                                       at com.android.internal.app.ResolverActivity$LoadIconTask.doInBackground(ResolverActivity.java:2471)
                                                       at com.android.internal.app.ResolverActivity$LoadIconTask.doInBackground(ResolverActivity.java:2459)
                                                       at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                       at java.lang.Thread.run(Thread.java:818) 
只有在我共享content.setTypetext/plain;时才会发生这种情况;。有人知道如何解决这个问题吗

编辑:

String shareBody = "really? I'm sending you a code to our awesome app!\nYour key:"
                                    + " "/* get key*/ + " Get started:" + " https://url";
编辑2:好的,显然这只发生在我的三星galaxy s7上,而不是像素上。我还注意到日志还显示:

    09-24 14:48:44.888 31968-31968/? E/MotionRecognitionManager: mSContextService = android.hardware.scontext.ISContextService$Stub$Proxy@e2ecc0
09-24 14:48:44.888 31968-31968/? E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@1417df9
09-24 14:48:44.888 31968-31968/? E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@1417df9

使用此代码与其他应用共享文本

private void share() {
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    String shareBody ="your message";
    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "subject");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
    sharingIntent.setType("text/plain");
    startActivity(Intent.createChooser(sharingIntent, "Share via"));
}

您的共享文本是否包含一些图像或可绘制的内容?它包括\n字符和一个urlSome文本,其中包含\n字符和一个url。我在本例中喜欢:您可以添加您的共享体吗?如果您想隐藏url,只需添加url来代替url即可