尝试使用intent共享文本时出现异常

时间:2017-09-24 11:34:23

标签: java android android-intent

我有按摩我希望用户与其他应用分享,所以我执行以下操作:

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) 

问题是我从系统中得到一个异常,我无法弄清楚我做错了什么:

sharingIntent.setType("text/plain");

只有当我String shareBody = "really? I'm sending you a code to our awesome app!\nYour key:" + " "/* get key*/ + " Get started:" + " https://url"; 时才会发生这种情况。有谁知道如何解决这个问题?

编辑:

    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

编辑2:好的,显然它只发生在我的三星galaxy s7而不是像素上。我还注意到日志还显示:

str.replace(/href="[^\s>"]+/, function(match) { return match+'"' });

1 个答案:

答案 0 :(得分:1)

使用此代码与其他应用分享文字。

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"));
}