我正在为我的应用程序制作一个菜单,使用DrawerLayout和ArrayAdapter子类来实现看起来像Facebook的抽屉菜单.
我目前在创建列表时没有任何问题,但现在看起来不错,我想在不同类型的选项(即用户相关选项和应用程序相关选项)和菜单顶部的搜索栏之间添加分隔符.
我当前的ArrayAdaptor子类的代码如下:
public class DrawerMenuAdapter extends ArrayAdapter<String>{
private Context context;
private String[] values;
private int resId;
public DrawerMenuAdapter(Context context, int textViewResourceId, String[] values) {
super(context, textViewResourceId, values);
this.context = context;
this.values = values;
this.resId = textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(this.resId, parent, false);
TextView elementText = (TextView)rowView.findViewById(R.id.element_text);
ImageView elementImage = (ImageView)rowView.findViewById(R.id.element_icon);
String textValue = values[position];
elementText.setText(textValue);
//This switch adds the icons to the related …
Run Code Online (Sandbox Code Playgroud) android separator android-layout android-listview android-adapter
我正在尝试使用GCM服务向我的设备发送推送通知.
我已经关注了服务器端函数的Android Hive教程(现在已经不像其他许多问题和答案一样被弃用),这些函数看起来按预期工作,因为我可以得到这种输出:
{"multicast_id":9131068334342174816,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1377441098827443%1d84a26ff9fd7ecd"}]}
Run Code Online (Sandbox Code Playgroud)
但根据一些答案,接收此响应只意味着GCM服务器已接受该消息进行发送,但并未发送该消息.所以,正如预期的那样,我BroadcastReceiver
没有收到任何东西.
这是我的BroadcastReceiver
代码:
public class GcmBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("gcm_debug", "PushReceiver onReceive called");
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String msgType = gcm.getMessageType(intent);
if(!extras.isEmpty()){
if(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(msgType)){
Log.i("gcm_debug", "Message send error");
}else if(GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(msgType)){
Log.i("gcm_debug", "Message deleted");
}else if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(msgType)){
Log.i("gcm_debug", "Message received : " + extras.toString());
}
}
setResultCode(Activity.RESULT_OK);
}
}
Run Code Online (Sandbox Code Playgroud)
我的AndroidManifest
:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" …
Run Code Online (Sandbox Code Playgroud) 我一直在尝试将最新的Google Play服务库添加到我的Android Studio项目中,以便使用推送消息和Maps API.
由于有很多关于如何在Eclipse和CLI中包含此库的教程,因此没有关于如何在Android Studio上包含最新库的说明.
我一直在寻找许多网站,其中一个看起来最合适的答案就是这个,因为其他的似乎记录了旧版本,但它看起来仍然像我遗漏了一些东西.
我试图将这个库包含在我将Facebook库包含到我的项目中的方式相同(对于Android Studio而言,这比GooglePlay更难记录),但它仍然看起来像我错过了一些东西.
为此,我已将整个文件夹复制<android-sdk>\extras\google\google_play_services\libproject\google-play-services_lib
到我的文件夹中<project-path>\libraries\google-play-services_lib
然后在Studio中,我尝试在模块>添加>导入模块中添加复制的文件夹,如Facebook文档或提供的链接中所述.我必须忘记像gradle文件,检查模块属性,我真的不知道我正在用这个lib做什么.
编辑:我在Android Studio上工作.