Google+ media sharing throws exception "No Activity found to handle the intent"

517 views Asked by At

i have tried sharing images with g+ android sdk

PlusShare.Builder share = new PlusShare.Builder(this);
share.setText("hello everyone!");
share.addStream(imageUri);
share.setType(mime);
startActivityForResult(share.getIntent(), 0);

Ref link here Here

But it throws exception No activity found to handle this intent. Exception

    06-11 06:15:30.038  13636-13636/xdk.reviewpush.consumer W/System.err﹕ android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.android.gms.plus.action.SHARE_GOOGLE flg=0x80000 pkg=com.google.android.gms (has extras) }
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1781)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.app.Activity.startActivityForResult(Activity.java:3745)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.app.Activity.startActivityForResult(Activity.java:3706)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at xdk.reviewpush.consumer.utils.CommonMethods.shareGooglePlus(CommonMethods.java:546)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at xdk.reviewpush.consumer.fragments.UploadPhotosFragment$11.onClick(UploadPhotosFragment.java:799)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.support.v7.app.AlertController$AlertParams$3.onItemClick(AlertController.java:807)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.widget.AdapterView.performItemClick(AdapterView.java:305)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.widget.AbsListView$PerformClick.run(AbsListView.java:3053)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.widget.AbsListView$3.run(AbsListView.java:3860)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5254)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    06-11 06:15:30.040  13636-13636/xdk.reviewpush.consumer W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    06-11 06:15:30.078  13636-13636/xdk.reviewpush.consumer W/ViewRootImpl﹕ Dropping event due to no window focus: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_ALT_RIGHT, scanCode=100, metaState=META_ALT_ON|META_ALT_RIGHT_ON, flags=0x8, repeatCount=25544, eventTime=1642612, downTime=177934, deviceId=1, source=0x301 }
    06-11 06:15:30.682  13636-13636/xdk.reviewpush.consumer A/GoogleApiClientConnecting﹕ GoogleApiClient connecting is in step STEP_VALIDATING_ACCOUNT but received callback for step STEP_GETTING_REMOTE_SERVICE
2

There are 2 answers

0
Arun On

Yup
Here is the final solution for sharing multiple images.
Method also contains sharing text only if image is not present.

public void shareGooglePlus(Activity mActivity,String mMessage, LinkedHashMap<Integer, Uri> mHashMapImageReference){
    boolean isMediaPresent = false;
    int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mActivity);
    if (errorCode != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(errorCode, mActivity, 0).show();
    } else {
        PlusShare.Builder builder = new PlusShare.Builder(mActivity);

        // Set the share text.
        if (mMessage != null)
            builder.setText(mMessage);

        String mime = null;
        ContentResolver cr = mActivity.getContentResolver();

        for(Map.Entry<Integer, Uri> entry : mHashMapImageReference.entrySet()){

            Uri mUri = entry.getValue();
            if (mUri != null) {
                builder.addStream(mUri);
                mime = cr.getType(mUri);
                builder.setType(mime);
                isMediaPresent = true;
            }
        }

        Intent mIntent = builder.getIntent();
        if(!isMediaPresent){
            mIntent.setType("text/plain");
            builder.setContentDeepLinkId("sometext");
        }

        try {
            mActivity.startActivityForResult(mIntent, 0);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
3
NavinRaj Pandey On

try this way:

Intent shareIntent = new PlusShare.Builder(this)
            .setText("some text")       
            .setContentDeepLinkId("TEXT_WITH_NOSPACE",
                    "some text",
                    "some Description",
                    Uri.parse("yourUri"))
            .getIntent();
    startActivityForResult(shareIntent, 0);