我知道已经有很多问题是这样的,我读了所有这些问题,但无论如何都无法找到解决方案。我做了什么:
我从http://developer.android.com/google/play-services/setup.html#Install完成了所有这些步骤以安装google play sdk 在我的项目属性Android选项卡中我有“谷歌播放服务库”确定,在Java Builder路径:“Android私人库”我有google-play-service.jar,这个库被选中。我也做了导入lib项目。
我从http://developer.android.com/google/gcm/client.html获取的测试代码。 我的清单文件:
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.intent.RECEIVE" />
<permission
android:name="lt.vaziouju.vaziuoju.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="lt.vaziouju.vaziuoju.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key here" />
<receiver
android:name="lt.vaziouju.vaziuoju.GcmBroadcastReceiver"
android:permission="lt.vaziouju.vaziuoju.c2dm.permission.SEND" >
<intent-filter>
<action android:name="lt.vaziouju.vaziuoju.c2dm.intent.RECEIVE" />
<category android:name="lt.vaziouju.vaziuoju" />
</intent-filter>
</receiver>
<service android:name="lt.vaziouju.vaziuoju.GcmIntentService" />
<activity
...
</activity>
</application>
我的java代码: 包lt.vaziouju.vaziuoju;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class Test_GCM extends Activity {
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
private static final String TAG = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test__gcm);
TextView mDisplay = (TextView) findViewById(R.id.display);
Context context = getApplicationContext();
// Check device for Play Services APK.
if (checkPlayServices()) {
// If this check succeeds, proceed with normal processing.
// Otherwise, prompt user to get valid Play Services APK.
}
}
// You need to do the Play Services APK check here too.
@Override
protected void onResume() {
super.onResume();
checkPlayServices();
}
/**
* Check the device to make sure it has the Google Play Services APK. If
* it doesn't, display a dialog that allows users to download the APK from
* the Google Play Store or enable it in the device's system settings.
*/
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test__gcm, menu);
return true;
}
}
如果你知道我怎么做,那将是一件事。我知道我在android编程方面不够好,刚刚开始学习GCM,但我已经花了6个小时阅读谷歌,什么都没有。
感谢您的任何想法。
答案 0 :(得分:3)
您使用的是Eclipse吗?如果Eclipse看到一个用于编译的jar文件,它不一定将它包含在apk中。 (你必须在几个地方提到罐子,通常人们不记得有多少个地方。)
点击项目名称 - 构建路径 - 配置构建路径 - 订单和导出。
同一个对话框有一个Projects选项卡,您可以在此处指定您所依赖的项目。
如果这不起作用,请将jar放入项目的libs子目录中。