2016-03-01 75 views
-1

智能手表如何接收手机短信?我正在寻找类似的应用程序,我不知道从哪里开始。我想为我的平板电脑制作一个应用程序,以显示短信通知。短信安卓应用

回答

1

要创建传送到连接的Android Wear设备的通知,您需要使用位于Support v4-Package中的NotificationCompat类。 详细的文档如何做到这一点可以找到here

代码基本上分解为此代码段(从文档复制):

int notificationId = 001; 
// Build intent for notification content 
Intent viewIntent = new Intent(this, ViewEventActivity.class); 
viewIntent.putExtra(EXTRA_EVENT_ID, eventId); 
PendingIntent viewPendingIntent = 
     PendingIntent.getActivity(this, 0, viewIntent, 0); 

NotificationCompat.Builder notificationBuilder = 
     new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.ic_event) 
     .setContentTitle(eventTitle) 
     .setContentText(eventLocation) 
     .setContentIntent(viewPendingIntent); 

// Get an instance of the NotificationManager service 
NotificationManagerCompat notificationManager = 
     NotificationManagerCompat.from(this); 

// Build the notification and issues it with notification manager. 
notificationManager.notify(notificationId, notificationBuilder.build()); 

这产生在手持设备上的通知以及连接Android Wear装置,甚至不需要创建磨损应用内。配对和传输过程由OS处理。

作为一般提示,Android开发人员的培训部分始终是开始研究的好地方。

+0

我没有任何运气成功实现NotificationCompat.Builder。您是否熟悉蓝牙配置文件?我一直在阅读有关MAP(消息访问配置文件)的信息,它允许在设备之间交换消息。想知道我是否可以走这条路? – Danielle

+0

可以更详细地描述你的问题?此方法的先决条件是,您已使用Android Wear应用程序将Smartwatch连接到手机。我没有在Android上使用任何低级蓝牙服务。如果你想传输比通知更复杂的数据,你应该使用谷歌服务,以确保在多个设备上的兼容性,请参阅http://developer.android.com/training/wearables/data-layer/index.html – Phoca