我不知道如何让我的项目中的GCM工作在android studio中。
当我使用GCM的一些章节时,你得到这个:无法解析符号GCMRegistrar 在这段代码中:
GCMRegistrar.checkDevice(this);
并没有显示导入该类的选项。
这是我的分档文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.0'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.2.42'
}
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.compage.womenshield"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<permission android:name="com.compage.womenshield.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.compage.womenshield.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/icono_app"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.compage.womenshield.Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCgQNclD9ZqxhiJXGdFvTTx2OiR_vKfJCM"/>
<receiver
android:name=".GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.javapapers.android" />
</intent-filter>
</receiver>
<service android:name="com.compage.womenshield.notification.GCMIntentService" />
</application>
</manifest>
这里显示错误:
<receiver
android:name=".GCMBroadcastReceiver"
在clase名称中。在这里:
<service android:name="com.compage.womenshield.notification.GCMIntentService" />
如何在android studio中使用这些gcm类?
答案 0 :(得分:4)
答案 1 :(得分:0)
你正在使用旧的方式。你应该检查谷歌的official documentatio n以在你的应用中使用gcm。现在,实例ID用于获取令牌
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
要获得完整教程,您可以查看tutorial