使用Glass GDK实施Google+时出错

时间:2015-01-16 20:51:06

标签: android-intent google-plus google-glass google-gdk

我目前正在尝试在Glass应用中集成将照片分享到Google Plus的功能。我一直在遵循集成google plus平台与android的集成说明:https://developers.google.com/+/mobile/android/getting-started

我已经完成了共享功能:https://developers.google.com/+/mobile/android/share/

以及共享媒体(我只想使用默认标题分享设备中的所有照片):https://developers.google.com/+/mobile/android/share/media

我已经在谷歌开发者控制台下启动了我的谷歌应用程序以及导入谷歌播放服务到Android工作室。我不断得到涉及没有活动来处理意图的错误:

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

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

我在清单中允许以下内容:

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

以下是我主要活动中的代码:

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


}

我还在一个安装了Google Plus并在其上运行的实际Glass设备上测试我的所有代码。我想知道问题是否可能与使用Android和GDK中缺少的东西之间存在差异?我到处搜索过,似乎无法在Glass上实现Google + plus功能的共享。我可以在GDK文档中找到的唯一示例使用了我不想使用的Mirror API。任何帮助将不胜感激!!!!

1 个答案:

答案 0 :(得分:1)

截至目前,GDK尚不支持动作发送和分享。

功能请求已提交herehere

Google Play尚未提供Google Play服务。

请参阅this issueWhy is Glass missing Google Play Services?

对不起,我认为在写这篇文章时你的想法是不可能的。