2017-02-07 3 views
-4

Я хочу поделиться изображением в своем приложении.Не удается разрешить метод 'setContentUrl'

Это мой файл макета

activity_xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.dc.google.MainActivity"> 

    <Button 
     android:id="@+id/share_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Share on Google+" 
     /> 

    </RelativeLayout> 

Это мой ява файл класса

MainActivity.java

package com.example.dc.google; 

import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.widget.Button; 


public class MainActivity extends AppCompatActivity { 
    Button button; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     final Button shareButton = (Button) findViewById(R.id.share_button); 
     shareButton.setOnClickListener(new android.view.View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       // Launch the Google+ share dialog with attribution to your app. 
       Intent shareIntent = shareButton.setText("Welcome to Google+") 
        .setContentUrl(Uri.parse("https://developers.google.com/+/")) 
        .getIntent(); 

       startActivityForResult(shareIntent,0); 
      } 
     }); 
    } 
} 

Здесь .setContentUrl показывает ошибку говоря the method can not be resolved.
Я не могу найти решение.
Как устранить эту ошибку?

+1

Ну, на что вы пытаетесь называть этот метод? 'setText' - это метод void ... –

+0

И когда вы говорите, что не можете найти что-то. 1) Прочтите сообщение об ошибке. Там много чего не так с этими тремя строками кода. 2) Прочтите документацию по API. 3) Что заставляет вас думать, что 'setContentUrl' является допустимым методом вообще? –

ответ

0

Нужно read the documentation снова ...

Вы не setText на кнопке должен ... Вы setText на new PlusShare.Builder

Беспокойства о совместном использовании изображения, как только вы получите код, который будет компилировать. (Подсказка: эта документация также показывает sharing images).

Button shareButton = (Button) findViewById(R.id.share_button); 
shareButton.setOnClickListener(new OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     // Launch the Google+ share dialog with attribution to your app. 
     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); 
    } 
});