34
GooglePlayService 7.8 & new tech in M ted

google play service 7.8 & new tech in M

Embed Size (px)

Citation preview

Page 1: google play service 7.8 & new tech in M

GooglePlayService 7.8 & new tech in M

ted

Page 2: google play service 7.8 & new tech in M

Nearby Message API

Agenda

Page 3: google play service 7.8 & new tech in M

Nearby Message

Page 4: google play service 7.8 & new tech in M

What is Nearby Message?

Page 5: google play service 7.8 & new tech in M

Subscribe hello

Page 6: google play service 7.8 & new tech in M
Page 7: google play service 7.8 & new tech in M

Nearby.Messages.publish(mGoogleApiClient, mDeviceInfoMessage, PUB_SUB_STRATEGY) .setResultCallback(new ResultCallback<Status>() {

@Override public void onResult(Status status) { if (status.isSuccess()) { Log.i(TAG, "published successfully"); // Send a message to the handler to change state when done // publishing. sendMessageToHandler(Constants.NO_LONGER_PUBLISHING, Constants.TTL_IN_MILLISECONDS); } else { Log.i(TAG, "could not publish"); handleUnsuccessfulNearbyResult(status); } } });

mGoogleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext()) .addApi(Nearby.MESSAGES_API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build();

Page 8: google play service 7.8 & new tech in M
Page 9: google play service 7.8 & new tech in M

mGoogleApiClient = new GoogleApiClient.Builder(getActivity().getApplicationContext()) .addApi(Nearby.MESSAGES_API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build();

Nearby.Messages.subscribe(mGoogleApiClient, mMessageListener, PUB_SUB_STRATEGY) .setResultCallback(new ResultCallback<Status>() {

@Override public void onResult(Status status) { if (status.isSuccess()) { Log.i(TAG, "subscribed successfully"); sendMessageToHandler(Constants.NO_LONGER_SUBSCRIBING, Constants.TTL_IN_MILLISECONDS); } else { Log.i(TAG, "could not subscribe"); handleUnsuccessfulNearbyResult(status); } } });

Page 10: google play service 7.8 & new tech in M

Nearby Connection

Page 11: google play service 7.8 & new tech in M

廣播

尋找廣播找到廣播,並要求連接

連結

連結完成

Page 12: google play service 7.8 & new tech in M

Advertising deviceNearby.Connections.startAdvertising(mGoogleApiClient, name, appMetadata, TIMEOUT_ADVERTISE, this).setResultCallback(new ResultCallback<Connections.StartAdvertisingResult>() { @Override public void onResult(Connections.StartAdvertisingResult result) { }});

<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >

<!-- Required for Nearby Connections API --> <meta-data android:name="com.google.android.gms.nearby.connection.SERVICE_ID" android:value="@string/service_id" />

......</application>

Page 13: google play service 7.8 & new tech in M

Nearby.Connections.startDiscovery(mGoogleApiClient, serviceId, TIMEOUT_DISCOVER, this) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { });

Discover device

Page 14: google play service 7.8 & new tech in M

@Overridepublic void onEndpointFound(final String endpointId, String deviceId, String serviceId, final String endpointName) { }

Nearby.Connections.sendConnectionRequest(mGoogleApiClient, myName, endpointId, myPayload, new Connections.ConnectionResponseCallback() { @Override public void onConnectionResponse(String endpointId, Status status, byte[] bytes) { } }, this);

找到裝置

send 連線 request

Page 15: google play service 7.8 & new tech in M

Nearby.Connections.rejectConnectionRequest(mGoogleApiClient, endpointId);

Nearby.Connections.acceptConnectionRequest(mGoogleApiClient, endpointId, payload, MainActivity.this) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { });

接受

拒絕

Page 16: google play service 7.8 & new tech in M

FACE API

Page 17: google play service 7.8 & new tech in M

ImageView myImageView = (ImageView) findViewById(R.id.imgview);BitmapFactory.Options options = new BitmapFactory.Options();options.inMutable=true;Bitmap myBitmap = BitmapFactory.decodeResource( getApplicationContext().getResources(), R.mipmap.img, options);

show img

Paint myRectPaint = new Paint();myRectPaint.setStrokeWidth(5);myRectPaint.setColor(Color.RED);myRectPaint.setStyle(Paint.Style.STROKE);

init face rect

Bitmap tempBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Bitmap.Config.RGB_565);Canvas tempCanvas = new Canvas(tempBitmap);tempCanvas.drawBitmap(myBitmap, 0, 0, null);

create canvas , so we can draw rect on it later

FaceDetector faceDetector = new FaceDetector.Builder(getApplicationContext()).build();Frame frame = new Frame.Builder().setBitmap(myBitmap).build();SparseArray<Face> faces = faceDetector.detect(frame);

for(int i=0; i<faces.size(); i++) { Face thisFace = faces.valueAt(i); float x1 = thisFace.getPosition().x; float y1 = thisFace.getPosition().y; float x2 = x1 + thisFace.getWidth(); float y2 = y1 + thisFace.getHeight(); tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myRectPaint);}myImageView.setImageDrawable(new BitmapDrawable(getResources(),tempBitmap));

use facedetector to detect face position and draw it on canvas

Page 18: google play service 7.8 & new tech in M
Page 19: google play service 7.8 & new tech in M
Page 20: google play service 7.8 & new tech in M
Page 21: google play service 7.8 & new tech in M

Barcode API

Page 22: google play service 7.8 & new tech in M

ImageView myImageView = (ImageView) findViewById(R.id.imgview2);Bitmap myBitmap = BitmapFactory.decodeResource( getApplicationContext().getResources(), R.mipmap.barcode);myImageView.setImageBitmap(myBitmap);

BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext()) .setBarcodeFormats(Barcode.QR_CODE) .build();Frame frame = new Frame.Builder().setBitmap(myBitmap).build();SparseArray<Barcode> barcodes = detector.detect(frame);

Barcode thisCode = barcodes.valueAt(0);TextView txtView = (TextView) findViewById(R.id.txtContent);txtView.setText(thisCode.rawValue);

detect QR code

Page 23: google play service 7.8 & new tech in M

NearBy API

Page 24: google play service 7.8 & new tech in M

http://andraskindler.com/blog/2015/tinting_drawables/

Tint Drawable

Page 25: google play service 7.8 & new tech in M

PercentRelativeLayouthttps://plus.google.com/+AndroidDevelopers/posts/C8oaLunpEEj

Page 26: google play service 7.8 & new tech in M

deprecated

ACCESS_MOCK_LOCATION ACCESS_SURFACE_FLINGER AUTHENTICATE_ACCOUNTS BRICK CLEAR_APP_USER_DATA DEVICE_POWER FORCE_BACK GET_TOP_ACTIVITY_INFO HARDWARE_TEST INJECT_EVENTS INTERNAL_SYSTEM_WINDOW MANAGE_ACCOUNTS MANAGE_APP_TOKENS READ_HISTORY_BOOKMARKS READ_PROFILE READ_SOCIAL_STREAM READ_USER_DICTIONARY SET_ACTIVITY_WATCHER SET_ORIENTATION SET_POINTER_SPEED SUBSCRIBED_FEEDS_READ SUBSCRIBED_FEEDS_WRITE USE_CREDENTIALS WRITE_HISTORY_BOOKMARKS WRITE_PROFILE WRITE_SMS WRITE_SOCIAL_STREAM WRITE_USER_DICTIONARY

Page 27: google play service 7.8 & new tech in M

ACTION_INSTALL_PACKAGE require REQUEST_INSTALL_PACKAGE permission

Page 28: google play service 7.8 & new tech in M

StrictMode

a develop toolhttp://developer.android.com/reference/android/os/StrictMode.html

Page 29: google play service 7.8 & new tech in M

TextView

新增 breakstrategy

http://developer.android.com/reference/android/widget/TextView.html#setBreakStrategy(int)

Page 30: google play service 7.8 & new tech in M

requestUsageTimeReport(PendingIntent)requestUsageTimeReport(PendingIntent receiver)

Ask the the system track that time the user spends in the app being launched, and report it back once done.

Page 31: google play service 7.8 & new tech in M

ConnectivityManagerThe primary responsibilities of this class are to:

1. Monitor network connections (Wi-Fi, GPRS, UMTS, etc.)

2. Send broadcast intents when network connectivity changes

3. Attempt to "fail over" to another network when connectivity to a network is lost

4. Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks

5. Provide an API that allows applications to request and select networks for their data traffic

Page 32: google play service 7.8 & new tech in M

MODE_MULTI_PROCESS for sharepreference is deprecated

Page 33: google play service 7.8 & new tech in M

applinkshttp://developer.android.com/preview/features/app-linking.html

Page 34: google play service 7.8 & new tech in M

Testing