Hiển thị các bài đăng có nhãn API. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn API. Hiển thị tất cả bài đăng
[CSHARP] Instructions for push notifications using One Signal API
Xin chào các bạn, bài viết hôm nay mình sẽ hướng dẫn các bạn cách push notification cho website sử dụng API One Signal C#.
[CSHARP] Hướng Dẫn Push Notification Sữ Dụng API One Signal
One Signal giúp chúng ta dễ dàng gởi thông báo đến tất cả các webclient đã đăng ký nhận thông báo từ ứng dụng web của chúng ta.
Sử dụng One Sign sẽ giúp tăng SEO cho website của chúng ta, mỗi khi có bài viết mới thì người dùng dễ dàng nhận được thông báo một cách nhanh chóng.
Dưới đây là giao diện demo ứng dụng:
Trong ứng dụng trên, mình chỉ push các thông tin cơ bản, bao gồm:
Tiêu đề, nội dung, link khi mở vào, và hình ảnh bài viết (chỉ tích hợp chạy trên chrome).
Khi các bạn nhấn nút Push vào thì ứng dụng sẽ gởi thông báo đến tất cả các client đã đăng ký như hình bên dưới.
Đầu tiên, các bạn cần import thư viện vào từ Nuget:
PM> Install-Package OneSignal.CSharp.SDK
Các bạn cần lấy
ID app, API Sercet key từ setting của onesignal để thêm vào ứng dụng nhé.Và dưới đây là source code khi click vào
button Push Notification:using OneSignal.CSharp.SDK;
using OneSignal.CSharp.SDK.Resources;
using OneSignal.CSharp.SDK.Resources.Notifications;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Push_Notification_OneSignal
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_push_Click(object sender, EventArgs e)
{
var client = new OneSignalClient("Nhập Serect key của bạn"); // Nhập API Serect Key
var options = new NotificationCreateOptions_new();
options.AppId = new Guid("Nhập ID SignOne"); // Nhập My AppID của bạn
options.IncludedSegments = new List<string> { "All" };
options.Headings.Add(LanguageCodes.English, txt_title.Text);
options.Contents.Add(LanguageCodes.English, txt_content.Text);
options.Url = txt_link.Text;
options.ChromeWebImage = txt_url_image.Text;
var result = client.Notifications.Create(options);
MessageBox.Show(result.ToString());
}
}
}
Chúc mọi người thanh công với thủ thuật này.
[POWER AUTOMATE] Instructions for sending zalo messages from Excel files
Xin chào các bạn, bài viết hôm nay mình hướng dẫn các bạn cách gởi tin nhắn Zalo từ phần mềm Power Automate trên Windows.
[POWER AUTOMATE] Hướng dẫn tự động gởi tin nhắn zalo đọc dữ liệu từ file excel
Microsoft Flow hiện là Power Automate, công cụ quy trình làm việc dựa trên đám mây của Microsoft.Phần mềm có thể nhanh chóng tự động hóa bất kỳ quy trình hoặc tác vụ nào, cho phép nhân viên dễ dàng tự động hóa các quy trình với các nguồn được kết nối như Microsoft/Office 365.
Một số ứng dụng phổ biến trong doanh nghiệp:
- Tự động hóa quy trình kinh doanh.
- Gửi lời nhắc tự động cho các nhiệm vụ quá hạn.
- Di chuyển dữ liệu kinh doanh giữa các hệ thống theo lịch trình.
- Kết nối với gần 300 nguồn dữ liệu hoặc bất kỳ API.
- Tự động hóa các tác vụ trên máy tính cục bộ của mình như tính toán dữ liệu trong Excel.
[ANDROID] LỖ HỔNG ZERO-DAY CỦA ANDROID BỊ CÁC CÔNG TY PHÁP Y KHAI THÁC
Google đã tiết lộ rằng hai lỗ hổng bảo mật Android ảnh hưởng đến điện thoại thông minh Pixel của họ đã bị các công ty pháp y khai thác một cách tự nhiên.
Google đã tiết lộ rằng hai lỗ hổng bảo mật Android ảnh hưởng đến điện thoại thông minh Pixel của họ đã bị các công ty pháp y khai thác một cách tự nhiên.
Mặc dù gã khổng lồ công nghệ không tiết lộ bất kỳ thông tin nào khác về bản chất của các cuộc tấn công khai thác những thiếu sót này, nhưng những người duy trì GrapheneOS cho biết họ “đang bị các công ty pháp y tích cực khai thác một cách tự nhiên”.
“CVE-2024-29745 đề cập đến một lỗ hổng trong phần sụn fastboot được sử dụng để hỗ trợ mở khóa/nhấp nháy/khóa,” họ cho biết trong một loạt bài đăng trên X (trước đây là Twitter).
"Các công ty điều tra đang khởi động lại các thiết bị ở trạng thái Sau lần mở khóa đầu tiên sang chế độ khởi động nhanh trên Pixel và các thiết bị khác để khai thác các lỗ hổng ở đó rồi xóa bộ nhớ."
GrapheneOS lưu ý rằng CVE-2024-29748 có thể bị kẻ tấn công cục bộ lợi dụng để làm gián đoạn quá trình khôi phục cài đặt gốc được kích hoạt thông qua API quản trị thiết bị.
Tiết lộ này được đưa ra hơn hai tháng sau khi nhóm GrapheneOS tiết lộ rằng các công ty pháp y đang khai thác các lỗ hổng phần sụn ảnh hưởng đến điện thoại Google Pixel và Samsung Galaxy để đánh cắp dữ liệu và theo dõi người dùng khi thiết bị không ở trạng thái nghỉ.
Nó cũng kêu gọi Google giới thiệu tính năng tự động khởi động lại để khiến việc khai thác các lỗi phần sụn trở nên khó khăn hơn.
Google đã tiết lộ rằng hai lỗ hổng bảo mật Android ảnh hưởng đến điện thoại thông minh Pixel của họ đã bị các công ty pháp y khai thác một cách tự nhiên.
Các lỗ hổng zero-day có mức độ nghiêm trọng cao.
- CVE-2024-29745 - Lỗ hổng tiết lộ thông tin trong thành phần bootloader
- CVE-2024-29748 - Lỗ hổng leo thang đặc quyền trong thành phần chương trình cơ sở
Mặc dù gã khổng lồ công nghệ không tiết lộ bất kỳ thông tin nào khác về bản chất của các cuộc tấn công khai thác những thiếu sót này, nhưng những người duy trì GrapheneOS cho biết họ “đang bị các công ty pháp y tích cực khai thác một cách tự nhiên”.
“CVE-2024-29745 đề cập đến một lỗ hổng trong phần sụn fastboot được sử dụng để hỗ trợ mở khóa/nhấp nháy/khóa,” họ cho biết trong một loạt bài đăng trên X (trước đây là Twitter).
"Các công ty điều tra đang khởi động lại các thiết bị ở trạng thái Sau lần mở khóa đầu tiên sang chế độ khởi động nhanh trên Pixel và các thiết bị khác để khai thác các lỗ hổng ở đó rồi xóa bộ nhớ."
GrapheneOS lưu ý rằng CVE-2024-29748 có thể bị kẻ tấn công cục bộ lợi dụng để làm gián đoạn quá trình khôi phục cài đặt gốc được kích hoạt thông qua API quản trị thiết bị.
Tiết lộ này được đưa ra hơn hai tháng sau khi nhóm GrapheneOS tiết lộ rằng các công ty pháp y đang khai thác các lỗ hổng phần sụn ảnh hưởng đến điện thoại Google Pixel và Samsung Galaxy để đánh cắp dữ liệu và theo dõi người dùng khi thiết bị không ở trạng thái nghỉ.
Nó cũng kêu gọi Google giới thiệu tính năng tự động khởi động lại để khiến việc khai thác các lỗi phần sụn trở nên khó khăn hơn.
Mọi người chủ ý và phòng tránh nhé, kể bị lộ thông tin cá nhân.
Theo TheHackerNews.Com
[ANDROID] Use Fused Location Provider Api for GPS positioning
Bài viết hôm nay, mình sẽ chia sẽ cho các bạn sử dụng thư viện Fused Location Api trong Android để định vị kinh độ và vĩ độ bằng GPS.
[ANDROID] Sử dụng Fused Location Provider Api để định vị GPS
Nếu các bạn, có đọc hay tìm hiểu về lấy latitude và longitude thì cách bình thường lấy là Implement LocationManager thì lấy vị trí tọa độ location ban đầu rất lâu.Nhưng nếu các bạn sử dụng Fused Location Api thông qua google services thì lấy rất là nhanh.
Đoan code MainActivity.java
package com.sakurafish.exam.location.api;
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsResult;
import com.google.android.gms.location.LocationSettingsStatusCodes;
import com.sakurafish.exam.location.api.databinding.ActivityMainBinding;
import java.text.DateFormat;
import java.util.Date;
/**
* Retrieve current location using Google Play Services Location API
* Based on "https://github.com/googlesamples/android-play-location/tree/master/LocationUpdates"
*/
public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener {
protected static final String TAG = "location-updates-sample";
/**
* 10秒間隔で位置情報を更新。実際には多少頻度が多くなるかもしれない。
*/
public static final long UPDATE_INTERVAL_IN_MILLISECONDS = 10000;
/**
* 最速の更新間隔。この値より頻繁に更新されることはない。
*/
public static final long FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS =
UPDATE_INTERVAL_IN_MILLISECONDS / 2;
private final static String REQUESTING_LOCATION_UPDATES_KEY = "requesting-location-updates-key";
private final static String LOCATION_KEY = "location-key";
private final static String LAST_UPDATED_TIME_STRING_KEY = "last-updated-time-string-key";
private static final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1;
private static final int REQUEST_CHECK_SETTINGS = 10;
private ActivityMainBinding mBinding;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
private Location mCurrentLocation;
private Boolean mRequestingLocationUpdates;
private String mLastUpdateTime;
private String mLatitudeLabel;
private String mLongitudeLabel;
private String mLastUpdateTimeLabel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
mLongitudeLabel = getResources().getString(R.string.longitude_label);
mLastUpdateTimeLabel = getResources().getString(R.string.last_update_time_label);
mRequestingLocationUpdates = false;
mLastUpdateTime = "";
updateValuesFromBundle(savedInstanceState);
buildGoogleApiClient();
}
private void updateValuesFromBundle(Bundle savedInstanceState) {
Log.i(TAG, "Updating values from bundle");
if (savedInstanceState != null) {
if (savedInstanceState.keySet().contains(REQUESTING_LOCATION_UPDATES_KEY)) {
mRequestingLocationUpdates = savedInstanceState.getBoolean(
REQUESTING_LOCATION_UPDATES_KEY);
setButtonsEnabledState();
}
if (savedInstanceState.keySet().contains(LOCATION_KEY)) {
mCurrentLocation = savedInstanceState.getParcelable(LOCATION_KEY);
}
if (savedInstanceState.keySet().contains(LAST_UPDATED_TIME_STRING_KEY)) {
mLastUpdateTime = savedInstanceState.getString(LAST_UPDATED_TIME_STRING_KEY);
}
updateUI();
}
}
protected synchronized void buildGoogleApiClient() {
Log.i(TAG, "Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
createLocationRequest();
}
protected void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
public void startUpdatesButtonHandler(View view) {
clearUI();
if (!isPlayServicesAvailable(this)) return;
if (!mRequestingLocationUpdates) {
mRequestingLocationUpdates = true;
} else {
return;
}
if (Build.VERSION.SDK_INT < 23) {
setButtonsEnabledState();
startLocationUpdates();
return;
}
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
setButtonsEnabledState();
startLocationUpdates();
} else {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.ACCESS_FINE_LOCATION)) {
showRationaleDialog();
} else {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
}
}
}
public void stopUpdatesButtonHandler(View view) {
if (mRequestingLocationUpdates) {
mRequestingLocationUpdates = false;
setButtonsEnabledState();
stopLocationUpdates();
}
}
private void startLocationUpdates() {
Log.i(TAG, "startLocationUpdates");
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
// 現在位置の取得の前に位置情報の設定が有効になっているか確認する
PendingResult result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback() {
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// 設定が有効になっているので現在位置を取得する
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, MainActivity.this);
}
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// 設定が有効になっていないのでダイアログを表示する
try {
status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way
// to fix the settings so we won't show the dialog.
break;
}
}
});
}
private void setButtonsEnabledState() {
if (mRequestingLocationUpdates) {
mBinding.startUpdatesButton.setEnabled(false);
mBinding.stopUpdatesButton.setEnabled(true);
} else {
mBinding.startUpdatesButton.setEnabled(true);
mBinding.stopUpdatesButton.setEnabled(false);
}
}
private void clearUI() {
mBinding.latitudeText.setText("");
mBinding.longitudeText.setText("");
mBinding.lastUpdateTimeText.setText("");
}
private void updateUI() {
if (mCurrentLocation == null) return;
mBinding.latitudeText.setText(String.format("%s: %f", mLatitudeLabel,
mCurrentLocation.getLatitude()));
mBinding.longitudeText.setText(String.format("%s: %f", mLongitudeLabel,
mCurrentLocation.getLongitude()));
mBinding.lastUpdateTimeText.setText(String.format("%s: %s", mLastUpdateTimeLabel,
mLastUpdateTime));
}
protected void stopLocationUpdates() {
Log.i(TAG, "stopLocationUpdates");
// The final argument to {@code requestLocationUpdates()} is a LocationListener
// (http://developer.android.com/reference/com/google/android/gms/location/LocationListener.html).
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
setButtonsEnabledState();
startLocationUpdates();
} else {
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
mRequestingLocationUpdates = false;
Toast.makeText(MainActivity.this, "このアプリの機能を有効にするには端末の設定画面からアプリの位置情報パーミッションを有効にして下さい。", Toast.LENGTH_SHORT).show();
} else {
showRationaleDialog();
}
}
break;
}
}
}
private void showRationaleDialog() {
new AlertDialog.Builder(this)
.setPositiveButton("許可する", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
}
})
.setNegativeButton("しない", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "位置情報パーミッションが許可されませんでした。", Toast.LENGTH_SHORT).show();
mRequestingLocationUpdates = false;
}
})
.setCancelable(false)
.setMessage("このアプリは位置情報の利用を許可する必要があります。")
.show();
}
public static boolean isPlayServicesAvailable(Context context) {
// Google Play Service APKが有効かどうかチェックする
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
if (resultCode != ConnectionResult.SUCCESS) {
GoogleApiAvailability.getInstance().getErrorDialog((Activity) context, resultCode, 2).show();
return false;
}
return true;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK:
startLocationUpdates();
break;
case Activity.RESULT_CANCELED:
break;
}
break;
}
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
public void onResume() {
super.onResume();
isPlayServicesAvailable(this);
// Within {@code onPause()}, we pause location updates, but leave the
// connection to GoogleApiClient intact. Here, we resume receiving
// location updates if the user has requested them.
if (mGoogleApiClient.isConnected() && mRequestingLocationUpdates) {
startLocationUpdates();
}
}
@Override
protected void onPause() {
super.onPause();
// Stop location updates to save battery, but don't disconnect the GoogleApiClient object.
if (mGoogleApiClient.isConnected()) {
stopLocationUpdates();
}
}
@Override
protected void onStop() {
stopLocationUpdates();
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i(TAG, "onConnected");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
if (mCurrentLocation == null) {
mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
updateUI();
}
if (mRequestingLocationUpdates) {
startLocationUpdates();
}
}
@Override
public void onLocationChanged(Location location) {
Log.i(TAG, "onLocationChanged");
mCurrentLocation = location;
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
updateUI();
Toast.makeText(this, getResources().getString(R.string.location_updated_message), Toast.LENGTH_SHORT).show();
}
@Override
public void onConnectionSuspended(int i) {
// The connection to Google Play services was lost for some reason. We call connect() to
// attempt to re-establish the connection.
Log.i(TAG, "Connection suspended");
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// Refer to the javadoc for ConnectionResult to see what error codes might be returned in
// onConnectionFailed.
Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = " + connectionResult.getErrorCode());
}
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putBoolean(REQUESTING_LOCATION_UPDATES_KEY, mRequestingLocationUpdates);
savedInstanceState.putParcelable(LOCATION_KEY, mCurrentLocation);
savedInstanceState.putString(LAST_UPDATED_TIME_STRING_KEY, mLastUpdateTime);
super.onSaveInstanceState(savedInstanceState);
}
}
File Activity_main.xml
<!--?xml version="1.0" encoding="utf-8"?-->
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.sakurafish.kotlin.example.MainActivity">
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin">
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:baselinealigned="false" android:orientation="horizontal">
<button android:id="@+id/start_updates_button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginend="10dp" android:layout_marginright="10dp" android:gravity="center" android:onclick="startUpdatesButtonHandler" android:text="@string/start_updates">
</button><button android:id="@+id/stop_updates_button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_marginleft="@dimen/small_margin" android:layout_marginstart="@dimen/small_margin" android:enabled="false" android:gravity="center" android:onclick="stopUpdatesButtonHandler" android:text="@string/stop_updates">
<textview android:id="@+id/latitude_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="@dimen/small_margin" android:layout_marginstart="@dimen/small_margin" android:textsize="@dimen/default_text_size">
<textview android:id="@+id/longitude_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="@dimen/small_margin" android:layout_marginstart="@dimen/small_margin" android:textsize="@dimen/default_text_size">
<textview android:id="@+id/last_update_time_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="@dimen/small_margin" android:layout_marginstart="@dimen/small_margin" android:textsize="@dimen/default_text_size">
</textview></textview></textview></button></linearlayout></linearlayout></layout>
File androidManifest.xml
<!--?xml version="1.0" encoding="utf-8"?-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sakurafish.exam.location.api">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION">
<application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN">
<category android:name="android.intent.category.LAUNCHER">
</category></action></intent-filter>
</activity>
</application>
</uses-permission></manifest>
Qua những đoạn code phía trên bạn cũng đã có sơ bộ một chút về tiện ích đó rồi.
Theo LapTrinhVB
[C#] Use Polly library to resend http request on error
Xin chào các bạn, bài viết hôm nay mình xin giới thiệu các bạn thư viện Polly, dùng để gửi lại request http api khi lỗi request xảy ra: web api lỗi, rớt mạng, timeout...
[C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
Ví dụ: Khi các bạn sử dụng http request để lấy dữ liệu tự API Server, nhưng nếu lúc này api đang bị lỗi 503-Service Unavailable.
Thì chúng ta làm sao, nó tiếp tục request thêm n lần: 3,4,5... đảm bảo chúng ta luôn luôn lấy được dữ liệu.
Nếu bình thường, chúng ta tự code thì cũng đơn giản như sau:
private readonly HttpClient _client = new HttpClient();
public async Task<HttpResponseMessage> SendRequestWithRetry()
{
HttpResponseMessage response;
var sendCount = 0;
do
{
var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://laptrinhvb.net"));
response = await _client.SendAsync(request);
sendCount++;
}
while (sendCount < 10 && response.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable);
return response;
}
Ở source này, các bạn thấy mình sử dụng cấu trúc lệnh do...while để gởi, nếu gởi nó sẽ tiếp tục gởi tiếp 10 lần.
Trong này này mình giới thiệu các bạn thư viện Polly chuyên dụng thể thực hiện công việc này.
Các bạn, cài đặt thư viện Polly từ nuget:
dotnet add package Polly
Ở hình trên các bạn thấy khi nó request lỗi, nó sẽ tiếp tục request tiếp. Source code demo C#, Console:
using Polly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Retry_requests_poly
{
internal class Program
{
static async Task Main()
{
var data = await MakeHttpRequestWithRetry("http://127.0.0.1:8081/pages/login.html?1152");
Console.WriteLine("Done!");
Console.Read();
}
static async Task<string> MakeHttpRequestWithRetry(string apiUrl)
{
var retryPolicy = Policy
.Handle<HttpRequestException>()
.WaitAndRetryAsync(60, retryAttempt => TimeSpan.FromSeconds(retryAttempt),
(exception, timeSpan, context) =>
{
Console.WriteLine($"Error: {exception.Message}");
Console.WriteLine($"Waiting for internet connection. Retrying in {timeSpan.TotalSeconds} seconds...");
});
//.WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(retryAttempt));
try
{
var data = await retryPolicy.ExecuteAsync(async () =>
{
using (HttpClient httpClient = new HttpClient())
{
HttpResponseMessage response = await httpClient.GetAsync(apiUrl);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine("Received data: " + responseBody);
return responseBody;
}
});
return data;
}
catch (HttpRequestException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
return null;
}
}
}
Chúc các bạn thành công.
PASSWORD UNZIP:
HUNG.PRO.VNTheo LapTrinhVB.Net
[C#] Cách thanh toán qua mã vạch VietQR sử dụng payOS API
Xin chào các bạn, bài viết hôm nay mình hướng dẫn các bạn cách tạo thanh toán hóa đơn trực tiếp qua mã vạch VietQR sử dụng payOS API.
[C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
Các bạn có thể đăng ký api payOS hoàn toàn miễn phí tại website.
Các bạn, thường mua hàng ở các website, khi thanh toán các bạn thường gặp có thể thanh toán trực tiếp bằng cách quét mã vạch như: Momo, Zalopay, Viettel money...
https://payos.vn
Các bạn, thường mua hàng ở các website, khi thanh toán các bạn thường gặp có thể thanh toán trực tiếp bằng cách quét mã vạch như: Momo, Zalopay, Viettel money...
Những Api này thường bạn đăng ký phải là tổ chức doanh nghiệp.
Với payOS, mình có thể đăng ký một tài khoản cá nhân bình thường, cách bước thực hiện các bạn đăng nhập vào website và tạo một tài khoản và liên kết ngân hàng như hướng dẫn.
Để viết bài này, mình đã đăng ký một tài khoản Ngân Hàng Phương Đông (OCB) để liên kết với payOS.
Khi các bạn đăng ký thành công, có bạn sẽ có các thông tin: clientID, apiKey, checkSumKey.
Để các bạn sử dụng gọi API.
Khi tạo một kênh thanh toán, sẽ có thông tin như hình bên dưới:
Và ở C# chúng ta sẽ cài đặt thư viện payOS từ nuget:
dotnet add package payOS --version 1.0.2
Các bạn khai báo thông tin cấu hình vào:
namespace DemoPayOS
{
public class Constants
{
public static string clientId = "";
public static string apiKey = "";
public static string checksumKey = "";
}
}
Dưới đây là source code ứng dụng demo, thường các bạn sẽ build trên Website, nhưng bài viết này mình demo ở Winform netCore 6
using Net.payOS;
using Net.payOS.Types;
using System.Diagnostics;
namespace DemoPayOS
{
public partial class Form1 : Form
{
PayOS payOS;
public Form1()
{
InitializeComponent();
payOS = new PayOS(Constants.clientId, Constants.apiKey, Constants.checksumKey);
}
private async void btnTaoLinkTT_ClickAsync(object sender, EventArgs e)
{
var name = txtSanPham.Text;
var soluong = Convert.ToInt32(txtSoluong.Text);
var thanhtien = Convert.ToInt32(txtThanhTien.Text);
ItemData item = new ItemData(name, soluong, thanhtien);
List<ItemData> items = new List<ItemData>();
items.Add(item);
var noidung = "Thanh toán tiền nhậu";
var orderID = 2005;
var tongGiaTien = 2000; // 2 ngàn vnđ
PaymentData paymentData = new PaymentData(orderID, tongGiaTien, noidung,
items, "https://localhost:3002", "https://localhost:3002");
CreatePaymentResult createPayment = await payOS.createPaymentLink(paymentData);
var linkCheckOut = createPayment.checkoutUrl;
Process.Start(new ProcessStartInfo
{
FileName = @"C:\Program Files\Google\Chrome\Application\chrome.exe",
Arguments = linkCheckOut
});
}
}
}
Khi tạo thành công, chúng ta sẽ được một đường link api website thanh toán, và chúng ta sẽ mở cho khách hàng thanh toán. Giao diện thanh toán:
Các bạn có thể nhấn nút Hủy thanh toán, để hủy bỏ đơn hàng này.
payOS cũng cung cấp cho chúng ta http callback, để chúng ta có thể cập nhật tình trạng thông tin đơn hàng đã được thanh toán hay hủy bỏ vào cơ sở dữ liệu của mình.
Khi các bạn đăng ký thành công, payOS có tài liệu hướng dẫn các sử dụng cụ thể, chi tiết các bạn có thể tham khảo ở trên đó.
P/s: Bài viết chỉ mang tính hướng dẫn, không có tính quảng cáo cho payOS api hay vietQR gì, chi tiết các bạn đọc kỹ ở phần đăng ký payOS trên trang chủ.
Chúc các bạn thành công.
Password Unzip:
HUNG.PRO.VNTheo LapTrinhVB.Net








![[ANDROID] Use Fused Location Provider Api for GPS positioning [ANDROID] Use Fused Location Provider Api for GPS positioning](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoEypfInam8UYf7-wg7D46rz4gNOKT8aZqEjjirfcBm55FckbvUNi8cso_fZcQFiyFoLPCr6G24qiqYKesYQtPuDXUTN0sLpMjyF-dR687hcOT7_Up45S2kHNxOOyrT0wLcrUalwQ0F7ObAO8JXnaRSgfYKNS7Grj1zD7tamLzrSExMoyEBB1iAC0hM3I/s16000-rw/Believe%20in%20it%20and%20act%20as%20if%20it%20could%20not%20fail.%20(1).png)





