简体   繁体   中英

Social Integration not working in Android App with TabGroupActivity

I have developed an android application with TabGroupActivity ( See this for example ) and everything works fine except Social Networking integration like Facebook and Twitter.

This Error was recorded in Stackoverflow before here and here and here

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.

PS:Everything worked fine before implementing TabGroupActivity

UPDATE 1: In the Manifest file i updated the code as follows as:

 <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"  />

But the Exception still gives: the launchMode of the caller is singleInstance

Why So..??

UPDATE 2: Now I kept debugging points inside LoginActivity of Facebook SDK. In that for getCallingPackage() , I get 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();
    }

Can anyone explain this behavior..?? I have been stuck on this from days.

Paste this code.It is working on those applications install in ur phone.

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

Last time i had this error, it was because i launched facebook's LoginActivity with wrong parameters, use this part of xml:

<activity
        android:name="com.facebook.LoginActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

I had this error when i launched LoginActivity with launchMode singleInstance (or something like that). Check this out.

Edit: I have one more thought... when you try to call facebook pass context not of local activity (one in tab), but try to pass context of parent activity (it will be TagGroupActivity).

<activity
  android:name="xx.yy.YourActivity"
  android:launchMode="singleTask"
/>

(try singleTask instead of singleInstance) I had the same issue in the past, but I rechecked my manifest and cant find any launchMode there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM