List of usage examples for android.os Message toString
@Override
public String toString()
From source file:org.frb.sf.frbn.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//* w w w.j a v a 2s .c o m*/ private static void generateNotification(Context context, Message message) { //int icon = R.drawable.ic_stat_gcm; //long when = System.currentTimeMillis(); Log.i(TAG, "Received message: " + message.toString()); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //Intent notificationIntent = new Intent(context, MainActivity.class); Intent notificationIntent = new Intent(context, MessageListActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); Notification notification = new NotificationCompat.Builder(context).setTicker("Message from FRB") .setAutoCancel(true).setContentTitle(message.getTitle()).setContentText(message.getMessageBody()) .setSmallIcon(R.drawable.ic_launcher).setContentIntent(intent).build(); // .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)) // notification.flags |= Notification.FLAG_AUTO_CANCEL; /* Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); */ //notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:io.v.android.apps.account_manager.AccountActivity.java
private void getIdentity() { if (mAccountName == null || mAccountName.isEmpty()) { replyWithError("Empty account name."); return;//ww w. j ava 2 s. c o m } Account[] accounts = AccountManager.get(this).getAccountsByType("com.google"); Account account = null; for (int i = 0; i < accounts.length; i++) { if (accounts[i].name.equals(mAccountName)) { account = accounts[i]; } } if (account == null) { replyWithError("Couldn't find Google account with name: " + mAccountName); return; } AccountManager.get(this).getAuthToken(account, OAUTH_SCOPE, new Bundle(), false, new OnTokenAcquired(), new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { replyWithError("Error getting auth token: " + msg.toString()); return true; } })); }
From source file:com.iiitd.networking.UDPMessenger.java
/** * Sends a broadcast message (TAG EPOCH_TIME message). Opens a new socket in case it's closed. * @param message the message to send (multicast). It can't be null or 0-characters long. * @return/*from w ww.j a va2 s . c om*/ * @throws IllegalArgumentException */ public boolean sendMessage(String message) throws IllegalArgumentException { if (message == null || message.length() == 0) throw new IllegalArgumentException(); // Check for WiFi connectivity ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWifi == null || !mWifi.isConnected()) { Log.d(DEBUG_TAG, "Sorry! You need to be in a WiFi network in order to send UDP multicast packets. Aborting."); return false; } // Check for IP address WifiManager wim = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int ip = wim.getConnectionInfo().getIpAddress(); // Create the send socket if (socket == null) { try { socket = new DatagramSocket(); } catch (SocketException e) { Log.d(DEBUG_TAG, "There was a problem creating the sending socket. Aborting."); e.printStackTrace(); return false; } } // Build the packet DatagramPacket packet; Message msg = new Message(TAG, message); byte data[] = msg.toString().getBytes(); WifiInfo wifiInfo = wim.getConnectionInfo(); int ipa = wifiInfo.getIpAddress(); String ipAddress = Formatter.formatIpAddress(ipa); try { // packet = new DatagramPacket(data, data.length, InetAddress.getByName(ipToString(ip, true)), MULTICAST_PORT); packet = new DatagramPacket(data, data.length, InetAddress.getByName(ipAddress), MULTICAST_PORT); } catch (UnknownHostException e) { Log.d(DEBUG_TAG, "It seems that " + ipToString(ip, true) + " is not a valid ip! Aborting."); e.printStackTrace(); return false; } try { socket.send(packet); } catch (IOException e) { Log.d(DEBUG_TAG, "There was an error sending the UDP packet. Aborted."); e.printStackTrace(); return false; } return true; }
From source file:io.v.android.impl.google.services.blessing.BlessingActivity.java
private void getBlessing() { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS); if (permissionCheck == PackageManager.PERMISSION_DENIED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.GET_ACCOUNTS }, REQUEST_CODE_USER_APPROVAL); return;//from w ww.j ava2s .c o m } Account[] accounts = AccountManager.get(this).getAccountsByType("com.google"); Account account = null; for (int i = 0; i < accounts.length; i++) { if (accounts[i].name.equals(mGoogleAccount)) { account = accounts[i]; } } if (account == null) { replyWithError("Couldn't find Google account with name: " + mGoogleAccount); return; } AccountManager.get(this).getAuthToken(account, OAUTH_SCOPE, new Bundle(), false, new OnTokenAcquired(), new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { replyWithError("Error getting auth token: " + msg.toString()); return true; } })); }
From source file:io.v.android.apps.syncslides.SignInActivity.java
private void fetchUserProfile() { if (!FETCH_PROFILE) { fetchUserProfileDone(null);/*w ww .ja v a2 s . c om*/ return; } AccountManager manager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); Account[] accounts = manager.getAccountsByType("com.google"); Account account = null; for (int i = 0; i < accounts.length; i++) { if (accounts[i].name.equals(mAccountName)) { account = accounts[i]; break; } } if (account == null) { Log.e(TAG, "Couldn't find Google account with name: " + mAccountName); pickAccount(); return; } manager.getAuthToken(account, OAUTH_SCOPE, new Bundle(), false, new OnTokenAcquired(), new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { Log.e(TAG, "Error getting auth token: " + msg.toString()); fetchUserProfileDone(null); return true; } })); }
From source file:com.synchophy.ui.CoverFlowActivity.java
private void refresh() { new JSONTask(this, true) { @Override/*ww w .j av a2s . co m*/ public void post(Message obj) throws JSONException { Log.e("CoverFlowActivity", obj.toString()); String token = JSONRequest.getToken(CoverFlowActivity.this); JSONArray images = (JSONArray) obj.obj; String[] imageGetParams = new String[images.length()]; String[] albumLabels = new String[images.length()]; String[] albumArtists = new String[images.length()]; for (int i = 0; i < images.length(); i++) { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); JSONObject imageDef = (JSONObject) images.get(i); nameValuePairs.add(new BasicNameValuePair("k", token)); nameValuePairs.add(new BasicNameValuePair("artist", imageDef.getString("artist"))); nameValuePairs.add(new BasicNameValuePair("album", imageDef.getString("album"))); nameValuePairs.add(new BasicNameValuePair("a", "view")); final String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8"); imageGetParams[i] = paramString; albumLabels[i] = imageDef.getString("album"); albumArtists[i] = imageDef.getString("artist"); Intent msgIntent = new Intent(CoverFlowActivity.this, ImageDownloadService.class); msgIntent.putExtra(ImageDownloadService.IMAGE_URL, paramString); startService(msgIntent); } ImageAdapter coverImageAdapter = (ImageAdapter) coverFlow.getAdapter(); coverImageAdapter.refresh(imageGetParams, albumLabels, albumArtists); coverImageAdapter.notifyDataSetChanged(); } }.execute("image", new BasicNameValuePair("a", "list"), new BasicNameValuePair("filter", Boolean.toString(PlayerManager.isFiltering()))); }
From source file:autobahn.WebSocketWriter.java
/** * Call this from the foreground (UI) thread to make the writer * (running on background thread) send a WebSocket message on the * underlying TCP./*from w ww . j a v a 2 s . c o m*/ * * @param message Message to send to WebSockets writer. An instance of the message * classes inside WebSocketMessage or another type which then needs * to be handled within processAppMessage() (in a class derived from * this class). */ public void forward(Object message) { Message msg = obtainMessage(); msg.obj = message; System.out.println("Llega a forward " + msg.toString()); sendMessage(msg); }
From source file:com.ratebeer.android.gui.components.PosterService.java
private void callbackMessenger(Intent intent, int result) { if (intent.hasExtra(EXTRA_MESSENGER)) { // Prepare a message Messenger callback = intent.getParcelableExtra(EXTRA_MESSENGER); Message msg = Message.obtain(); msg.arg1 = result;/* w ww . j a v a2s .c om*/ try { // Send it back to the messenger, i.e. the activity callback.send(msg); } catch (RemoteException e) { Log.e(com.ratebeer.android.gui.components.helpers.Log.LOG_NAME, "Cannot call back to activity to deliver message '" + msg.toString() + "'"); } } }
From source file:com.taobao.weex.bridge.WXBridgeManager.java
@SuppressWarnings("unchecked") private void invokeCallJSBatch(Message message) { if (mNextTickTasks.isEmpty() || !isJSFrameworkInit()) { if (!isJSFrameworkInit()) { WXLogUtils.e("[WXBridgeManager] invokeCallJSBatch: framework.js uninitialized!! message:" + message.toString()); }//w w w .j ava 2s. c o m return; } try { Object instanceId = message.obj; Object task = null; Stack<String> instanceStack = mNextTickTasks.getInstanceStack(); int size = instanceStack.size(); for (int i = size - 1; i >= 0; i--) { instanceId = instanceStack.get(i); task = mNextTickTasks.remove(instanceId); if (task != null && !((ArrayList) task).isEmpty()) { break; } } task = ((ArrayList) task).toArray(); WXJSObject[] args = { new WXJSObject(WXJSObject.String, instanceId), new WXJSObject(WXJSObject.JSON, WXJsonUtils.fromObjectToJSONString(task)) }; invokeExecJS(String.valueOf(instanceId), null, METHOD_CALL_JS, args); } catch (Throwable e) { WXLogUtils.e("WXBridgeManager", e); String err = "invokeCallJSBatch#" + WXLogUtils.getStackTrace(e); WXExceptionUtils.commitCriticalExceptionRT(null, WXErrorCode.WX_ERR_JS_FRAMEWORK.getErrorCode(), "invokeCallJSBatch", err, null); } // If task is not empty, loop until it is empty if (!mNextTickTasks.isEmpty()) { mJSHandler.sendEmptyMessage(WXJSBridgeMsgType.CALL_JS_BATCH); } }