我在尝试使用适用于 Android 的 Facebook SDK 时收到此错误。
这是我的执行调用:
new getBitmapFromUrl().execute("https://fs02.androidpit.info/userfiles/4110382/image/Android/android-6-0-marshmallow-hero-w782.jpg");
我的异步代码:
public class getBitmapFromUrl extends AsyncTask<String,String,Bitmap>{
@Override
protected Bitmap doInBackground(String... params) {
Bitmap bitmap = null;
URL url = null;
try {
url = new URL(params[0]);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoInput(true);
InputStream inputStream = con.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
SharePhoto sharePhoto = new SharePhoto.Builder()
.setBitmap(bitmap)
.build();
SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder()
.addPhoto(sharePhoto)
.build();
//shareButton is the facebookSdk default share button to call shareDialog
shareButton.setShareContent(sharePhotoContent);
}
}
这是我的回调方法:
shareButton.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.e("Status", result.toString());
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
Log.e("Status", error.toString());
}
});
还有我的 onActivity 回调:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
我的清单代码:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<provider
android:authorities="com.facebook.app.FacebookContentProvider1507510099556071"
android:name="com.facebook.FacebookContentProvider"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.FacebookActivity"/>
</application>
如果我的代码不正确,请提出一个很好的例子。:-)