2016-03-01 105 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