解决方法:
在EditText的父级控件中找一个,设置成
android:focusable="true"
android:focusableInTouchMode="true"
原来是Android Studio的JNI默认路径是这样的
//目录结构一定要改成这个样子
|---src
|---main
|---jniLibs
|---arm64-v8a
|---libhello-jni.so
|---armeabi
|---libhello-jni.so
|---armeabi-v7a
|---libhello-jni.so
|---x86
|---libhello-jni.so
|---x86_64
|---libhello-jni.so
|---mips
|---libhello-jni.so
|---mips64
|---libhello-jni.so
目录结构一定要改成上图的样子,详细的修改方法请转移 | Android Studio 添加动态库os文件的方法
直接修改build.gradle
文件如下:
android {
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
其实两种方法的原理是一样的。方法1是:直接将so文件放到了Android Studio 的默认路径src > main > jniLibs
方法2是:修改jniLibs
的默认路径为libs
<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="gcm.play.android.samples.com.gcmquickstart"/>
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->
<!-- [START gcm_listener] -->
<service
android:name=".MyGcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<!-- [END gcm_listener] -->
WakefulBroadcastReceiver that receives GCM messages and delivers them to an application-specific GcmListenerService subclass.
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("GCM Message")
.setContentText(message + count)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = Integer.parseInt(("" + System.currentTimeMillis()).substring(10));
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
注意,工程下载好后,里面默认代码使用的API Key以及Sender ID需要修改。API Key: GcmSender.java(模拟服务器向Google发送推送消息使用,后面可以不用main函数,直接用浏览器插件发消息的方式,更方便点。)Sender ID:RegistrationIntentService.java(代码默认使用的是”R.string.gcm_defaultSenderId”)。
02-23 10:39:18.709 19735-19763/gcm.play.android.samples.com.gcmquickstart I/RegIntentService: GCM Registration Token:
dnbhEeyYCWg:APA91bH_yYRmgPsuzpC7qMKp86JV3jR5d...Iw6VvPHilRa2d9u7sW4Xs6El2S1nsqtGM4yO2vVjHv-nSs_DkF3-sdn3b...7mxrbdsyl5xb53
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a GCM Topic Message!",
}
}
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "token",
"data": {
"message": "This is a GCM token Message!",
}
}
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"registration_ids": ["token1","token2"],
"data": {
"message": "This is a GCM token Message!",
}
}