google play service 7.8 & new tech in m

Post on 15-Feb-2017

291 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

GooglePlayService 7.8 & new tech in M

ted

Nearby Message API

Agenda

Nearby Message

What is Nearby Message?

Subscribe hello

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();

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); } } });

Nearby Connection

廣播

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

連結

連結完成

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>

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

Discover device

@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

Nearby.Connections.rejectConnectionRequest(mGoogleApiClient, endpointId);

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

接受

拒絕

FACE API

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

Barcode API

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

NearBy API

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

Tint Drawable

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

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

ACTION_INSTALL_PACKAGE require REQUEST_INSTALL_PACKAGE permission

StrictMode

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

TextView

新增 breakstrategy

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

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.

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

MODE_MULTI_PROCESS for sharepreference is deprecated

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

Testing

top related