четверг, 26 декабря 2013 г.
четверг, 5 декабря 2013 г.
Подключение Google Play Services к проекту в Android Studio
Проверяем установлены или нет в Android SDK Google Play services и Google Repository.
Проверяем переменную среды ANDROID_SDK_HOME, у меня почему то была C:\Users\Developer\AppData\Local\Android\android-studio\sdk
Проверяем переменную среды ANDROID_SDK_HOME, у меня почему то была C:\Users\Developer\AppData\Local\Android\android-studio\sdk
вместо
Смотрим версию Google Play services в папке Android SDK:
C:\Program Files\Android\android-studio\sdk\extras\google\m2repository
Видим, что последняя версия 4.0.30.
Открываем в Android Studio файл build.gradle проекта. Ищем dependencies:
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
Дописываем до такого вида:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.30'
}
Где указываем последнюю версию "4.0.30".
Сохраняем и нажимаем значок Sync Project with Gradle Files. (расположен левее значков AVD manager и SDK manager).
Открываем AndroidManifest.xml и в секцию <application> добавляем наследника:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" /><meta-data android:name="com.google.android.gms.version"
После чего должен нормально работать import com.google.android.gms.
пятница, 29 ноября 2013 г.
Печать текста в Android
Печать текста в Android через Google Cloud Print
Документация Google
Код:
@Override
protected Void doInBackground(Void... params) {
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
String user = "user@gmail.com";
String pass = "password";
String source = "Cloud%20Printing%20Test";
HttpGet authGet = new HttpGet(
"https://www.google.com/accounts/ClientLogin?accountType=HOSTED_OR_GOOGLE&Email="
+ user
+ "&Passwd="
+ pass
+ "&service=cloudprint&source=" + source);
HttpResponse httpResponse;
httpResponse = httpclient.execute(authGet);
String authResponse = EntityUtils
.toString(httpResponse.getEntity());
String authKey = authResponse.substring(authResponse
.indexOf("Auth=") + 5);
authKey = authKey.replace("\n", "");
MyLog.d(TAG, "Auth key: " + authKey);
HttpPost printPost = new HttpPost(
"https://www.google.com/cloudprint/submit?output=json");
printPost.setHeader("Authorization", "GoogleLogin auth=" + authKey);
printPost.setHeader("X-CloudPrint-Proxy", source);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("printerid", "ID"));
nameValuePairs.add(new BasicNameValuePair("title", "TEST"));
nameValuePairs.add(new BasicNameValuePair("capabilities", "{capabilities=[]}"));
// nameValuePairs.add(new BasicNameValuePair("content", getContent()));
// nameValuePairs.add(new BasicNameValuePair("contentType", "application/pdf"));
nameValuePairs.add(new BasicNameValuePair("content", "123"));
nameValuePairs.add(new BasicNameValuePair("contentType", "text/plain"));
printPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse printResponse = httpclient.execute(printPost);
String lol = EntityUtils.toString(printResponse.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Источник
Документация Google
Код:
@Override
protected Void doInBackground(Void... params) {
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
String user = "user@gmail.com";
String pass = "password";
String source = "Cloud%20Printing%20Test";
HttpGet authGet = new HttpGet(
"https://www.google.com/accounts/ClientLogin?accountType=HOSTED_OR_GOOGLE&Email="
+ user
+ "&Passwd="
+ pass
+ "&service=cloudprint&source=" + source);
HttpResponse httpResponse;
httpResponse = httpclient.execute(authGet);
String authResponse = EntityUtils
.toString(httpResponse.getEntity());
String authKey = authResponse.substring(authResponse
.indexOf("Auth=") + 5);
authKey = authKey.replace("\n", "");
MyLog.d(TAG, "Auth key: " + authKey);
HttpPost printPost = new HttpPost(
"https://www.google.com/cloudprint/submit?output=json");
printPost.setHeader("Authorization", "GoogleLogin auth=" + authKey);
printPost.setHeader("X-CloudPrint-Proxy", source);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("printerid", "ID"));
nameValuePairs.add(new BasicNameValuePair("title", "TEST"));
nameValuePairs.add(new BasicNameValuePair("capabilities", "{capabilities=[]}"));
// nameValuePairs.add(new BasicNameValuePair("content", getContent()));
// nameValuePairs.add(new BasicNameValuePair("contentType", "application/pdf"));
nameValuePairs.add(new BasicNameValuePair("content", "123"));
nameValuePairs.add(new BasicNameValuePair("contentType", "text/plain"));
printPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse printResponse = httpclient.execute(printPost);
String lol = EntityUtils.toString(printResponse.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Источник
вторник, 26 ноября 2013 г.
Как получить текст ссылки в webview если на ссылку нажали
Как получить текст ссылки в Webview если на неё нажали - shouldOverrideUrlLoading
http://developer.android.com/reference/android/webkit/WebViewClient.html
http://developer.android.com/reference/android/webkit/WebViewClient.html
четверг, 7 ноября 2013 г.
среда, 6 ноября 2013 г.
Библиотека TCP / UDP клиента/сервера для Java
kryonet TCP and UDP client/server library for Java https://code.google.com/p/kryonet/
Подписаться на:
Сообщения (Atom)