使用 Android 分享 Intent 在 Facebook 上分享视频

Posted

技术标签:

【中文标题】使用 Android 分享 Intent 在 Facebook 上分享视频【英文标题】:Video Sharing on Facebook using the Android share Intent 【发布时间】:2012-04-19 05:43:20 【问题描述】:

这个问题可能看起来很相似,但与“使用 Facebook sdk 在 Facebook 上共享视频”或“使用共享意图共享纯文本或图像”没有任何关系。 我在 SO ->

上关注了这些帖子

android share intent for Facebook

How to share photo with CAPTION via Android share intent on Facebook?

还有这个外部链接

http://sudarmuthu.com/blog/sharing-content-in-android-using-action_send-intent

并了解了 android 中的共享意图,可以启动它与 Android 手机上现有的共享应用程序共享图像/视频/文本。 我用这段代码在 facebook 上分享了图片:

package com.mypackage.share;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class FbshareActivity extends Activity 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("image/jpg");

        share.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///mnt/sdcard/tutu.jpg"));
        startActivity(Intent.createChooser(share, "Share Image"));
    

Manifest 文件如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mypackage.share"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".FbshareActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

效果很好。我可以在 facebook 上分享图片。

现在我要上传视频: 我替换了这一行: share.setType("image/jpg");

用这个share.setType("video/3gpp");

还有这个 share.putExtra(Intent.EXTRA_STREAM,Uri.parse("**file:///mnt/sdcard/dimg1333456357958.jpg"));** 用这个share.putExtra(Intent.EXTRA_STREAM,Uri.parse("**file:///mnt/sdcard/a123bghy4.3gpp"));**

但我在运行代码时遇到此错误:

/Environment(30996): getExternalStorageState/mnt/sdcard
E/Environment(30996): getExternalStorageList
W/MountService( 2879): getVolumeState(/mnt/sdcard/external_sd): Unknown volume
W/MountService( 2879): getVolumeState(/mnt/sdcard/external_sd): Unknown volume
E/Environment(30996): getExternalStorageState/mnt/sdcard
D/SurfaceFlinger( 2879): [JJ]removeSurface for sid=74 
D/dalvikvm(30996): GC_CONCURRENT freed 1106K, 19% free 8612K/10503K, paused 3ms+5ms
E/SurfaceFlinger( 2879): [JJ]SurfaceFlinger FPS: 24.994677
D/ACRA    (30996): Writing crash report file.
D/ACRA    (30996): Mark all pending reports as approved.
D/ACRA    (30996): Looking for error files in /data/data/com.facebook.katana/app_acra-reports
V/ACRA    (30996): About to start ReportSenderWorker from #handleException
D/ACRA    (30996): Add user comment to null
D/ACRA    (30996): #checkAndSendReports - start
D/ACRA    (30996): Looking for error files in /data/data/com.facebook.katana/app_acra-reports
I/ACRA    (30996): Sending file 1333628258000-approved.stacktrace
D/ACRA    (30996): Connect to https://www.facebook.com/mobile/android_crash_logs/
D/ACRA    (30996): Setting httpPost headers
D/ACRA    (30996): Sending request to https://www.facebook.com/mobile/android_crash_logs/
D/dalvikvm(30996): GC_CONCURRENT freed 631K, 18% free 8644K/10503K, paused 5ms+2ms
W/ResponseProcessCookies(30996): Invalid cookie header: "Set-Cookie: datr=ZY19T4_v6CV68jQn4FTduX_l; expires=Sat, 05-Apr-2014 12:17:41 GMT; path=/; domain=.facebook.com; httponly". Unable to parse expires attribute: Sat
E/SurfaceFlinger( 2879): [JJ]SurfaceFlinger FPS: 4.741684
D/BatteryService( 2879): update start
D/ACRA    (30996): #checkAndSendReports - finish
E/AndroidRuntime(30996): FATAL EXCEPTION: main
E/AndroidRuntime(30996): java.lang.NullPointerException
E/AndroidRuntime(30996):    at com.facebook.katana.service.method.VideoUpload.getRealPathFromURI(VideoUpload.java:144)
E/AndroidRuntime(30996):    at com.facebook.katana.service.method.VideoUpload.start(VideoUpload.java:165)
E/AndroidRuntime(30996):    at com.facebook.katana.binding.AppSession.postToService(AppSession.java:4212)
E/AndroidRuntime(30996):    at com.facebook.katana.service.method.VideoUpload.RequestVideoUpload(VideoUpload.java:73)
E/AndroidRuntime(30996):    at com.facebook.katana.activity.media.UploadVideoActivity.upload(UploadVideoActivity.java:209)
E/AndroidRuntime(30996):    at com.facebook.katana.activity.media.UploadVideoActivity.onClick(UploadVideoActivity.java:169)
E/AndroidRuntime(30996):    at android.view.View.performClick(View.java:3100)
E/AndroidRuntime(30996):    at android.view.View$PerformClick.run(View.java:11644)
E/AndroidRuntime(30996):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(30996):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(30996):    at android.os.Looper.loop(Looper.java:126)
E/AndroidRuntime(30996):    at android.app.ActivityThread.main(ActivityThread.java:4002)
E/AndroidRuntime(30996):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(30996):    at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(30996):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
E/AndroidRuntime(30996):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
E/AndroidRuntime(30996):    at dalvik.system.NativeStart.main(Native Method)
D/SurfaceFlinger( 2879): screenshot: sw=216, sh=135, minZ=0, maxZ=21015
W/ActivityManager( 2879):   Force finishing activity com.facebook.katana/.activity.media.UploadVideoActivity
D/SurfaceFlinger( 2879): screenshot: result = OK
E/android.os.Debug( 2879): Dumpstate > /data/log/dumpstate_app_com_facebook_katana_error
I/dumpstate(31581): begin
W/ActivityManager( 2879): Activity pause timeout for ActivityRecord40f51e68 com.facebook.katana/.activity.media.UploadVideoActivity
F//system/bin/logcat(31586): stack corruption detected: aborted
W/PowerManagerService( 2879): Timer 0x3->0x3|0x0
D/VoldCmdListener(   87): asec list
I/dumpstate(31581): done
D/InputTransport( 2879): channel '41014710 Sorry!    - Use *#9900# to take log - (server)' ~ mPointerStates->semaphore initialized 0x586ac000.
D/InputTransport( 2879): channel '41014710 Sorry!    - Use *#9900# to take log - (server)' ~ mPointerStates initialized 0x586ac000.
D/InputTransport( 2879): channel '41014710 Sorry!    - Use *#9900# to take log - (client)' ~ mPointerStates initialized 0x587f1000.
E/SurfaceFlinger( 2879): [JJ]SurfaceFlinger FPS: 0.207880
D/SurfaceFlinger( 2879): [JJ]createSurface for pid 31559 (1280 x 752)
D/SurfaceFlinger( 2879): [JJ]createSurface for pid 2879 (1 x 1)
E/SurfaceFlinger( 2879): [JJ]SurfaceFlinger FPS: 18.909105

如何调试 com.facebook.katana ? 请帮忙。 Rgds

【问题讨论】:

【参考方案1】:

显然有一个错误 --> http://bugs.developers.facebook.net/show_bug.cgi?id=16728 在 facebook 的共享意图中,我怀疑这是它不起作用的原因。 Rgds, 软软的

【讨论】:

以上是关于使用 Android 分享 Intent 在 Facebook 上分享视频的主要内容,如果未能解决你的问题,请参考以下文章

如何使用Android Intent System在whatsapp上分享最少n人的文本

Android:无法通过 Intent 分享图片

Android:通过 Intent.ACTION_SEND 分享(某事),然后自动返回我的应用

Android 信息分享实现

一起学Android之Intent

android 调用系统分享图片及文字