我开发了一个带有TabGroupActivity(See this for example)的Android应用程序,除了Facebook和Twitter等社交网络集成外,一切正常。
在here和here以及here之前的Stackoverflow中记录了此错误
java.lang.RuntimeException: Unable to resume activity {com.xxxx.xxxxx/com.facebook.LoginActivity}: com.facebook.FacebookException: Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance.
07-29 18:22:55.757: E/AndroidRuntime(2342): Caused by: com.facebook.FacebookException: Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance.
P.S:在实施TabGroupActivity
之前一切正常更新1:在清单文件中,我将代码更新如下:
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/com_facebook_loginview_log_in_button"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:launchMode="singleTask" />
但异常仍然给出:the launchMode of the caller is singleInstance
为什么这样...... ??
更新2:现在我在Facebook SDK的LoginActivity中保持调试点。对于getCallingPackage(),我得到 Null
String callingPackage = getCallingPackage();//Always Null
BackTracing it: On the Calling Activity (FacebookShare.java), I always get data as null instead of some values.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
//Toast.makeText(FacebookShareActivity.this, "onActivityResult", Toast.LENGTH_SHORT).show();
}
任何人都可以解释这种行为.. ??我几天都被困在这上面了。
答案 0 :(得分:2)
粘贴此代码。它正在处理那些安装在手机中的应用程序。
void share(String nameApp, String imagePath) {
try
{
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpeg"); // put here your mime type
if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by App Name");
targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)) );
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
}
catch(Exception e){
Log.v("VM","Exception while sending image on" + nameApp + " "+ e.getMessage());
}
}
答案 1 :(得分:1)
上次我有这个错误,那是因为我用错误的参数启动了facebook的LoginActivity,使用xml的这一部分:
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
当我使用launchMode singleInstance(或类似的东西)启动LoginActivity时出现此错误。看看这个。
编辑: 我还有一个想法...当你试图调用facebook pass context而不是本地活动时(tab中的一个),但是尝试传递父活动的上下文(它将是TagGroupActivity)。
答案 2 :(得分:0)
<activity
android:name="xx.yy.YourActivity"
android:launchMode="singleTask"
/>
(尝试使用singleTask而不是singleInstance) 我过去遇到了同样的问题,但我重新检查了清单,无法在那里找到任何launchMode。