我正在开发一个Android应用,并按照以下教程添加了Google登录功能:https://developers.google.com/identity/sign-in/android/sign-in
现在用户已登录,我希望能够读取和写入他们的Google Spreadsheets.我查看了电子表格API并告诉您使用OAuth授权请求:https://developers.google.com/google-apps/spreadsheets/?hl = zh- CN
从登录页面教程:
Google登录按钮可对用户进行身份验证并管理OAuth 2.0流程,从而简化您与Google API的集成.
我正在尝试使用Google登录页面进行授权.我现在可以使用GoogleApiClient成功登录和退出我的Google帐户,因此我尝试添加以下代码来访问我在用户登录时调用的电子表格:
private class RetrieveFeedTask extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... urls) {
SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1");
try {
URL SPREADSHEET_FEED_URL = new URL(urls[0]);
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
for (SpreadsheetEntry spreadsheet : spreadsheets) {
System.out.println(spreadsheet.getTitle().getPlainText());
}
} catch (ServiceException | IOException e) {
e.printStackTrace();
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我用这行称呼它:
new RetrieveFeedTask().execute("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
Run Code Online (Sandbox Code Playgroud)
但是在service.getFeed调用上我收到以下错误:
com.google.gdata.util.ParseException: Unrecognized content …
Run Code Online (Sandbox Code Playgroud) 我看了很多相关的问题,但似乎没有一个对我有用.
我正在尝试序列化UTC中的所有内容.这是我的代码:
class Class1
{
static void Main()
{
Class2 foo = new Class2();
JObject json = JObject.Parse(JsonConvert.SerializeObject(foo, new JsonSerializerSettings()
{
DateParseHandling = DateParseHandling.DateTimeOffset,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
DateTimeZoneHandling = DateTimeZoneHandling.Utc
}));
Console.WriteLine(json.ToString());
Console.Read();
}
}
class Class2
{
public DateTimeOffset time = new DateTimeOffset(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddTicks(14663484000000000));
public DateTimeOffset time2 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddTicks(14663484000000000);
public DateTime time3 = new DateTime(14663484000000000);
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
{
"time": "2016-06-19T08:00:00-07:00",
"time2": "2016-06-19T08:00:00-07:00",
"time3": "0047-06-20T15:00:00Z"
}
Run Code Online (Sandbox Code Playgroud)
这是我想要获得的输出: …
我正在使用Drive API,并开始变得非常沮丧.我正在尝试使用查询根据名称搜索文件/文件夹.这个演示有一个很好的例子来说明如何执行此操作:https://github.com/googledrive/android-demos/blob/master/src/com/google/android/gms/drive/sample/demo/QueryFilesWithAInTitleActivity.java
但我不想将数据添加到ListView,我只想直接从MetadataBufferResult中提取信息(标题和ID,以便我可以使用它们).但是我看过的每个例子都只是这个ListView的东西,而且我还没能找到从MetadataBufferResult中提取任何信息的方法或找到它的好文档.
基本上我希望能够这样做(代码取自上面链接的演示):
final private ResultCallback<DriveApi.MetadataBufferResult> metadataCallback =
new ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Problem while retrieving results");
return;
}
//I haven't been able to find a way to do this
result.getDriveID();
result.getFileTitle();
}
};
Run Code Online (Sandbox Code Playgroud)
简短版本:我想在某人的Drive帐户的根目录中搜索标题为"x"的文件,然后读/写此文件.我的问题是我无法从我传递的MetadataBufferResult对象中提取数据,我看到的所有示例都使用ListView输出它,我不想这样做.
android google-drive-api google-play-services google-drive-android-api
我正在尝试使用RecyclerView和TextView实现一个CoordinatorLayout,其中TextView会根据您滚动RecyclerView的方式进行动画处理。但是onDependentViewChanged
,尽管我滚动了RecyclerView,但在我的自定义行为中,仅在视图第一次膨胀时才被调用几次,此后才被调用。
我的行为:
public class Behavior extends CoordinatorLayout.Behavior<TextView> {
public Behavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {
return dependency instanceof RecyclerView;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
我的XML:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="blahhhhhhhhhhh"
app:layout_behavior="com.mypackage.Behavior"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) 我已经查看了具有相同错误的其他问题,但它们似乎都特定于该用户的情况.我无法找到问题的解决方案.
我在我的Android应用程序中使用gson将我的自定义对象列表保存到sharedPreferences中.对象非常基础:
public class Idea {
private String title;
private String details;
public Idea (String title, String details) {
this.title = title;
this.details = details;
}
public String getTitle() { return title; }
public void setTitle(String newTitle) { title = newTitle; }
public String getDetails() { return details; }
public void setDetails(String newDetails) { details = newDetails; }
}
Run Code Online (Sandbox Code Playgroud)
列表声明如下:
private static List<Idea> ideas = new ArrayList<Idea>();
Run Code Online (Sandbox Code Playgroud)
序列化似乎工作正常,但当我尝试在MainActivity中解码它时,如下所示:
String jsonIdeas = sharedPref.getString(IDEAS_KEY, null);
Gson gson = new Gson();
ideas = …
Run Code Online (Sandbox Code Playgroud) 我正在使用icu 项目的Transliterator类将半角字符转换为全角字符,如下所示:
\n\nTransliterator transliterator = Transliterator.getInstance("Hiragana-Katakana");\nString converted = transliterator.transliterate("\xef\xbd\xba\xef\xbe\x9d\xef\xbe\x86\xef\xbe\x81\xef\xbe\x8a"); //half-width\n
Run Code Online (Sandbox Code Playgroud)\n\n结果是converted
: \xe3\x82\xb3\xe3\x83\xb3\xe3\x83\x8b\xe3\x83\x81\xe3\x83\x8f (全角)
但:
\n\nString converted = transliterator.transliterate("\xe3\x82\xb3\xe3\x83\xb3\xe3\x83\x8b\xe3\x83\x81\xe3\x83\x8f"); //full-width\n
Run Code Online (Sandbox Code Playgroud)\n\n的结果converted
仍然是: \xe3\x82\xb3\xe3\x83\xb3\xe3\x83\x8b\xe3\x83\x81\xe3\x83\x8f (全角)
我的期望是\xef\xbd\xba\xef\xbe\x9d\xef\xbe\x86\xef\xbe\x81\xef\xbe\x8a
。谁能帮我解决这个问题吗?
谢谢。
\n