Sarah Wever
Sarah Wever

Reputation: 81

Error when implementing Google+ with Glass GDK

I am currently trying to integrate the ability to share photos to Google plus within a Glass app. I have been following the integration instructions for integrating google plus platform with android here: https://developers.google.com/+/mobile/android/getting-started

I have gone through implementing the share feature: https://developers.google.com/+/mobile/android/share/

as well as the sharing media (I just want to share any photo from the device with a default caption): https://developers.google.com/+/mobile/android/share/media

I have activated my google app under google developer console as well as imported google play services into android studio. I continuously get the errors that involve not having an activity to handle the intent:

01-16 12:29:40.447  30140-30140/com.example.sarahwever.sharemedia2pt0 E/InputEventSender﹕ Exception dispatching finished signal.
01-16 12:29:40.447  30140-30140/com.example.sarahwever.sharemedia2pt0E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
01-16 12:29:40.470  30140-30140/com.example.sarahwever.sharemedia2pt0 E/MessageQueue-JNI﹕ android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/plain flg=0x1 (has clip) (has extras) }

and

01-16 12:29:40.478  30140-30140/com.example.sarahwever.sharemedia2pt0 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.sarahwever.sharemedia2pt0, PID: 30140
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=text/plain flg=0x1 (has clip) (has extras) }

I have allowed the following in my manifest:

<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

And here is the code in my main activity:

import com.google.android.glass.media.Sounds;
import com.google.android.glass.widget.CardBuilder;
import com.google.android.glass.widget.CardScrollAdapter;
import com.google.android.glass.widget.CardScrollView;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
import com.google.android.gms.plus.PlusClient;
import com.google.android.gms.plus.PlusShare;

/**
 * An {@link Activity} showing a tuggable "Hello World!" card.
 * <p/>
 * The main content view is composed of a one-card {@link CardScrollView} that provides tugging
 * feedback to the user when swipe gestures are detected.
 * If your Glassware intends to intercept swipe gestures, you should set the content view directly
 * and use a {@link com.google.android.glass.touchpad.GestureDetector}.
 *
 * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
 */
public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    public static String TAG = "MainActivity";

    /**
     * {@link CardScrollView} to use as the main content view.
     */
    private CardScrollView mCardScroller;

    private View mView;

    /* Request code used to invoke sign in user interactions. */
    private static final int RC_SIGN_IN = 0;

    /* Client used to interact with Google APIs. */
    private GoogleApiClient mGoogleApiClient;

    /* A flag indicating that a PendingIntent is in progress and prevents
     * us from starting further intents.
     */
    private boolean mIntentInProgress;

    private static final int REQ_SELECT_PHOTO = 1;
    private static final int REQ_START_SHARE = 2;
    final private String mPicDir = Environment.getExternalStorageDirectory()+"/"+Environment.DIRECTORY_DCIM + "/Camera/*";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
                .addConnectionCallbacks(MainActivity.this)
                .addOnConnectionFailedListener(MainActivity.this)
                .addApi(Plus.API)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build();

        mView = buildView();

        mCardScroller = new CardScrollView(MainActivity.this);
        mCardScroller.setAdapter(new CardScrollAdapter() {
            @Override
            public int getCount() {
                return 1;
            }

            @Override
            public Object getItem(int position) {
                return mView;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                return mView;
            }

            @Override
            public int getPosition(Object item) {
                if (mView.equals(item)) {
                    return 0;
                }
                return AdapterView.INVALID_POSITION;
            }
        });
        // Handle the TAP event.
        mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Plays disallowed sound to indicate that TAP actions are not supported.
                AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                am.playSoundEffect(Sounds.SUCCESS);

                Intent shareIntent = new PlusShare.Builder(MainActivity.this)
                        .setType("text/plain")
                        .setText("Welcome to the Google+ platform.")
                        .setContentUrl(Uri.parse("https://developers.google.com/+/"))
                        .getIntent();

                startActivityForResult(shareIntent, 0);

                Intent photoPicker = new Intent(Intent.ACTION_PICK);
                photoPicker.setType("video/*, image/*");
                startActivityForResult(photoPicker, REQ_SELECT_PHOTO);
            }
        });
        setContentView(mCardScroller);
    }

    protected void onStart() {
        super.onStart();
        mGoogleApiClient.connect();
    }

    protected void onStop() {
        super.onStop();

        if (mGoogleApiClient.isConnected()) {
            mGoogleApiClient.disconnect();
        }
    }

    public void onConnectionFailed(ConnectionResult result) {
        if (!mIntentInProgress && result.hasResolution()) {
            try {
                mIntentInProgress = true;
                startIntentSenderForResult(result.getResolution().getIntentSender(),
                        RC_SIGN_IN, null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                // The intent was canceled before it was sent.  Return to the default
                // state and attempt to connect to get an updated ConnectionResult.
                mIntentInProgress = false;
                mGoogleApiClient.connect();
                Log.d(TAG, "did not connect");
            }
        }
    }

    public void onConnected(Bundle connectionHint) {
        // We've resolved any connection errors.  mGoogleApiClient can be used to
        // access Google APIs on behalf of the user.
    }

    protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
        if (requestCode == RC_SIGN_IN) {
            mIntentInProgress = false;

            if (!mGoogleApiClient.isConnecting()) {
                mGoogleApiClient.connect();
            }
        }

        super.onActivityResult(requestCode, responseCode, intent);

        if(requestCode == REQ_SELECT_PHOTO) {
            if(responseCode == RESULT_OK) {
                Uri selectedImage = intent.getData();
                ContentResolver cr = MainActivity.this.getContentResolver();
                String mime = cr.getType(selectedImage);

                PlusShare.Builder share = new PlusShare.Builder(MainActivity.this);
                share.setText("Sarah RULEZ!");
                share.addStream(selectedImage);
                share.setType(mime);
                startActivityForResult(share.getIntent(), REQ_START_SHARE);
            }
        }
    }

    public void onConnectionSuspended(int cause) {
        mGoogleApiClient.connect();
    }

        @Override
    protected void onResume() {
        super.onResume();
        mCardScroller.activate();
    }

    @Override
    protected void onPause() {
        mCardScroller.deactivate();
        super.onPause();
    }

    private View buildView() {
        CardBuilder card = new CardBuilder(MainActivity.this, CardBuilder.Layout.TEXT);

        card.setText(R.string.hello_world);
        Log.d(TAG, "hello world");
        return card.getView();
    }


}

I am also testing all of my code on an actual Glass device which has Google Plus installed and running on it. I'm wondering if the issue is perhaps with the differences between using android and something that's missing in the GDK? I've searched everywhere and cannot seem to find assistance with implementing the share to google plus feature on Glass. The only example I can find in the GDK documentation makes use of the Mirror API which I do not want to use. Any help would be greatly appreciated!!!!

Upvotes: 0

Views: 255

Answers (1)

pt2121
pt2121

Reputation: 11870

As of now, GDK does not support action send and share yet.

A feature request has been submitted here and here.

Also Google Play services is not available on Glass yet.

Please see this issue and Why is Glass missing Google Play Services?.

Sorry, I think your idea is not possible as of this writing.

Upvotes: 1

Related Questions