Uri*_*UVD 5 android facebook exception try-catch facebook-sdk-3.1
有人能告诉我在哪里设置一个try/catch来捕获它吗?
02-10 22:54:35.701: E/ActivityThread(787): Failed to find provider info for com.facebook.katana.provider.PlatformProvider
Run Code Online (Sandbox Code Playgroud)
我已经知道这是因为我没有在手机中安装facebook应用程序.
我想在抛出异常时做一个Toast这不起作用.
shareButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
try{
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(Archivo.this)
.setLink(pagina)
.setName(nombre)
.setPicture(photo)
.setDescription(brief)
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
catch(FacebookDialogException ex){
int duration = Toast.LENGTH_SHORT;
CharSequence FacebookDialogError="Instale y actualize su version de Facebook";
Toast toast = Toast.makeText(activity,FacebookDialogError , duration);
toast.show();
}
}
});
Run Code Online (Sandbox Code Playgroud)
我在facebookdialog收到异常的地方设置了相同的toast,它仍然无效.
public FacebookDialog build() {
validate();
Bundle extras = new Bundle();
putExtra(extras, NativeProtocol.EXTRA_APPLICATION_ID, applicationId);
putExtra(extras, NativeProtocol.EXTRA_APPLICATION_NAME, applicationName);
Intent intent = handleBuild(extras);
if (intent == null) {
int duration = Toast.LENGTH_SHORT;
CharSequence FacebookDialogError="Instale y aCtualize su version de Facebook";
Toast toast = Toast.makeText(activity,FacebookDialogError , duration);
toast.show();
throw new FacebookException("Unable to create Intent; this likely means the Facebook app is not installed.");
}
appCall.setRequestIntent(intent);
return new FacebookDialog(activity, fragment, appCall, getOnPresentCallback());
}
Run Code Online (Sandbox Code Playgroud)
如何制作该例外的Toast?
抱歉,如果现在回答我自己的问题为时已晚,但我即将更新出现此问题的应用程序。由于问题仍然存在,我将发布故障排除
这是在找不到 Facebook 应用程序时的后备措施。
private void publishFeedDialog(String Link,String Name,String Photo,String Descripcion) {
Bundle params = new Bundle();
params.putString("name", Name);
params.putString("caption",Caption);
params.putString("description",Descripcion);
params.putString("link", Link);
params.putString("picture",Photo);
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(sEstablecimiento.this,
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error == null) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(sEstablecimiento.this,
"Posted story, id: "+postId,
Toast.LENGTH_SHORT).show();
} else {
// User clicked the Cancel button
Toast.makeText(sEstablecimiento.this.getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
Toast.makeText(sEstablecimiento.this.getApplicationContext(),
"Publish cancelled",
Toast.LENGTH_SHORT).show();
} else {
// Generic, ex: network error
Toast.makeText(sEstablecimiento.this.getApplicationContext(),
"Error posting story",
Toast.LENGTH_SHORT).show();
}
}
})
.build();
feedDialog.show();
}
Run Code Online (Sandbox Code Playgroud)
并使用布尔值来测试是否可以构建 ShareDialog
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(myActivity.this)
.setLink("page")
.setName("name")
.setPicture("photo")
.setDescription("description")
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
publishFeedDialog("page","name","photo","description");
}
Run Code Online (Sandbox Code Playgroud)
我希望它对某人有用。感谢您的耐心并原谅我对这个问题的不关心。
| 归档时间: |
|
| 查看次数: |
5251 次 |
| 最近记录: |