Okay, great, we now have a UI defined
and our Android manifest is almost done.
But because we're using Google Services,
there is one meta tag that we need to
add, and that's just to specify that
we're using the Play Services Library.
We do that like this.
The metadata tag is used
within the application tag and
it should be a sibling of the activity,
not a child.
Within that, your specified Android is
com.google.android.gms.version, and
the value for this is
atInteger/GooglePlayServices_version.
Now as you can see here
it's showing up red.
It's showing up as an error
you cant resolve symbol,
but we're going to fix that in a moment.
And also once that's been fixed, once
your application has been configured to
use these services libraries
whenever you compile,
this will be filled in automatically
with the correct number.
So let's go ahead and do that.
So in order to do that there's one other
place that we need to ensure that we're
using the libraries for the services and
that's in the build.gradle for
the app itself.
So if I go into the build.gradle for
the app,
down here you can see the dependencies
at bottom of build.gradle.
We're going to add a new
dependency in here.
So what we want to add is quite simply,
to compile conduct
google.android.gms:play-services:6.5+.
Now it's important to note that
your version here may be different.
It depends on what you're using, and
what version of Play Services
you've installed.
You can take a look in your system to
see what versions have been installed
for you.
And I'm just using this plus,
just to make life a little bit easier.
I believe I have 6.5.0.87.
But of course, by the time your
watching this Play Services
might be in version 7 or later and as
you can see here, you should avoid using
plus in version numbers because it
can lead to unpredictable behavior.
But I'm just going to leave it in for
the time being, for simplicity.
But do note when you're building your
applications that you should use
the correct version number here.
So now, once we've done this, we're
going to go to our main activity, and
we're going to access
the location provider.
Now, in our main activity, remember that
it contains just a single text view.
When the user runs the app,
we want it to get the current
location using location services, and
write the latitude of the current
location into that text view.
In order to do this, we're going to
need to write some code in the activity.
This code will create
the Google API Client, and
set up the required call backs to catch
responses back from location services.
حسناً، رائع، لدينا الآن واجهة مستخدم
محددة وتم الانتهاء من بيان Android.
لكن لأننا نستخدم خدمات Google،
هناك علامة تعريف واحدة نحتاج
لإضافتها، وذلك لتحديد أنك تستخدم مكتبة
خدمات Play.
نقوم بها على هذا النحو.
يتم استخدام علامة التعريف
داخل علامة التطبيق
ولابد أن تكون تابعة للنشاط وليست فرعية.
داخل هذا، Android المحدد لديك هو
com.google.android.gms.version
وقيمة هذا هو
atInteger/GooglePlay خدمات_إصدار.
وكما ترى هنا تظهر باللون الأحمر.
تظهر في شكل خطأ لا يمكنك حل الرمز،
لكننا سنقوم بمعالجة ذلك في الحال.
وأيضاً بمجرد معالجة ذلك،
يتم تكوين تطبيقك
لكي يستخدم مكتبات الخدمات
وقتما تحول برمجياًُ،
سيتم إضافة الرقم الصحيح بطريقة تلقائية.
دعنا نبدأ ونفعل.
وحتى نقوم بذلك هناك مكان آخر
لابد أن نتأكد أننا
نستخدم المكتبات للخدمات وهذا في
تكوين .gradle
للتطبيق ذاته.
لذا إذا ذهبت إلى تكوين .gradle للتطبيق،
بالأسفل هنا يمكنك رؤية التبعيات في
أسفل تكوين .gradle.
سنقوم بإضافة تبعية جديدة هنا.
ما نريد إضافته شيء بسيط،
لتحويل الإجراء
google.android.gms:play-services:6.5+.
من المهم أن تلاحظ أن الإصدار لديك ربما
يكون مختلف.
يستند إلى ما تستخدمه
وأي إصدار خدمات Play
قمت بتثبييته.
يمكن أن تلقي نظرة في نظامك
لترى أي إصدارات تم تثبيتها
لأجلك.
استخدم هذه الإضافة لتسهيل الأمر.
أصدق أن لدي6.5.0.87..
لكن بالطبع، عند مشاهدتك خدمات Play
ربما تكون في الإصدار 7 أو ما بعده وكما ترى
هنا، لابد أن تتجنب استخدام
الإضافات في أعداد الإصدار لأنها يمكن أن
تؤدي إلى سلوك غير متوقع.
لكنني سأتركها هنا لمزيد من السهولة.
لكن عليك التأكد عند قيامك بتكوين تطبيقك
أنك تستخدم
رقم الإصدار الصحيح هنا.
الآن وبعد أن قمنا بذلك، سنذهب إلى
نشاطنا الرئيسي
والحصول على مزود الموقع.
الآن، في نشاطنا الرئيسي، تذكر أنه يحتوي
على طريقة عرض نص.
عندما يقوم المستخدم بتشغيل التطبيق،
نريد الحصول على الموقع الحالي باستخدام
خدمات الموقع،
كتابة خط عرض الموقع الحالي في طريقة
عرض النص.
وحتى نفعل ذلك، سنحتاج إلى كتابة بعض
التعليمات البرمجية في النشاط.
ستقوم التعليمة البرمجية بتكوين عميل
واجهة برمجة تطبيق
وإعداد إعادة الاستدعاءات المطلوبة لتخزين
الاستجابات من خدمات الموقع.
Certo, ótimo, agora temos uma IU
definida e o nosso manifesto Android
está quase pronto.
Mas porque nós estamos usando o Google
Services, há uma tag meta
que precisamos para adicionar,
e isso é apenas para
especificar que estamos usando a Play
Services Library.
E fazemos isso assim.
A tag de metadados é usada
dentro da tag do aplicativo
e deve ser uma irmã
da atividade, e não um filha.
Dentro disso, o seu Android especificado
é com.google.android.gms.version,
e o valor para isso é
atInteger/GooglePlayServices_version.
Agora, como você pode ver aqui,
está aparecendo em vermelho.
Está aparecendo como um erro,
você não pode resolver o símbolo,
mas nós vamos corrigir isso
em um momento.
E também uma vez isso tenha sido corrigido
e o seu aplicativo tenha sido
configurado para usar essas bibliotecas de serviços
sempre que você compilar,
isso será preenchido automaticamente
com o número correto.
Vamos continuar e fazer isso agora.
Portanto, a fim de fazer isso há um
outro lugar em que precisamos garantir
que estamos usando as bibliotecas
para os serviços,
e isso é no build.gradle
para o próprio aplicativo.
Se eu for dentro da build.gradle
para o aplicativo, aqui embaixo
você pode ver as dependências
na parte inferior do build.gradle.
Vamos adicionar uma nova
dependência aqui.
Então, o que nós queremos adicionar
é pura e simplesmente
para compilar
google.android.gms:play-services:6.5+.
É importante saber que a
sua versão aqui pode ser diferente.
Depende do que você está usando,
e qual a versão do Play Services
que você instalou.
Você pode dá uma olhada no
seu sistema para ver quais as versões que
você tem instaladas.
E eu só estou usando esse sinal de mais
para facilitar um pouco a vida.
Eu acho que tenho 6.5.0.87.
Mas é claro que, quando estiver
assistindo esses Play Services
podem estar na versão 7 ou posterior,
e como pode ver aqui,
você deve evitar o uso de +
em números de versão,
pois isso pode levar a um
comportamento imprevisível.
Mas eu vou deixar assim por
agora, para simplificar.
Mas observe que quando estiver criando
os seus aplicativos deverá usar
o número de versão correto aqui.
Então agora, depois de ter feito isso, vamos
para a nossa atividade principal,
e vamos acessar
o provedor de localização.
Agora, na nossa atividade principal,
lembre-se que ela contém apenas
uma única TextView.
Quando o usuário executa o aplicativo,
queremos que ele obtenha a localização atual
usando os serviços de localização
e grave a latitude do local atual
nessa TextView.
Para fazer isso,
precisaremos escrever
algum código na atividade.
Esse código criará
o cliente API do Google e
configurará os callbacks
necessários para obter respostas de volta
dos serviços de localização.
太棒了!我们现在定义了 UI 并且 Android 清单也即将完成
但因为我们正在使用 Google 服务 所以需要添加元标签
该标签规定我们使用 Play 服务库
我们像这样完成此操作
元数据标签在应用程序标签内使用
它应是 activity 的同级项 而不是子项
在该标签内 指定的 Android 是 com.google.android.gms.version
它的值是 atInteger/GooglePlayServices_version
现在 正如在这里看到的 它显示红色
它作为你无法解析符号的错误出现
但我们打算过一会修复它
此外 错误被修复后
如果应用程序已被配置为在编译时使用这些服务库
这里将以正确的编号自动填充
让我们继续并做这件事
为了完成此工作 在另一个地方我们需要确保
将这些库用于服务
并且处在应用本身的 build.gradle 中
如果进入应用的 build.gradle
往下这里可以看到 build.gradle 底部的依赖性
我们打算在这里添加一个新的依赖关系
我们要添加的东西只是
为了编译行为 google.android.gms:play-services:6.5+
现在 重要的是要注意你这里的版本可能不同
这取决于你使用什么
以及安装了 Play 服务的哪个版本
你可以看一下你的系统
了解安装了什么版本
我使用的是这个 plus 以便让工作变得更轻松
我认为版本是 6.5.0.87
但是 当你观看此视频时 Play 服务可能是第 7 版或更新版
正如在这里看到的 应避免使用带有 plus 的版本号
因为这会导致不可预知的行为
但目前我把它留在里面 只是为了简单起见
不过 在构建应用程序时
必须注意应使用正确的版本号
现在 在完成此工作后 我们打算转到主 activity
我们还打算访问定位提供者
现在 在主 activity 中要记住它只包含一个文本视图
当用户运行应用时
我们想让应用使用定位服务获得当前的位置
并且将当前位置的经度写入该文本视图
为此 需要在 activity 中编写某些代码
此代码将创建 Google API 客户端
并建立所需的回调 以捕捉从定位服务返回的响应