Wednesday, 31 March 2021

Run/install/debug Android applications over Wi-Fi ?

Open Teminal/cmd

--------------- Below steps is for Android 10 or lower

Step 1 - Connect the device via USB and make sure debugging is working;


Step 2 - run adb tcpip 5555  on teminal. 


Step 3 - run  adb shell netcfg  or  adb shell ifconfig



Step 4 - You can disconnect the USB now



Step 5 -  run adb connect <DEVICE_IP_ADDRESS>:5555


Ex : Wireless debugging - Ipaddress & Port(Screen shot)

according to above screen comment as below
(adb connect 192.168.29.77:5555 )


----------------- if Android 11 and Higher


Flow step for Android 11 or higher


you can see your device in Android studio without USB cable

Saturday, 19 December 2020

Retrofit2 in android


Dependencies 

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'

// additional things
implementation 'com.squareup.okhttp3:logging-interceptor:4.0.1'
implementation 'com.squareup.okhttp3:okhttp:4.0.1'

Need to create classes
ApiInterface.java
public interface ApiInterface {


@FormUrlEncoded
@POST("get-token")
Call<ResponseBody> getToken(@FieldMap Map<String, String> fieldMap);

}

ApiClient.java
public class ApiClient {

private static Retrofit retrofit;
private static Retrofit retrofitPlaid;

public static Retrofit getClient() {

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(
interceptor)
.readTimeout(
60, TimeUnit.MINUTES)
.writeTimeout(
60, TimeUnit.MINUTES)
.build();


retrofit = new Retrofit.Builder()
.baseUrl(
"service url")
.addConverterFactory(
GsonConverterFactory.create())
.client(
client)
.build();


return retrofit;
}

}

Implement in Activity or Service
# Create apiinterface object
ApiInterface apiService;
apiService = ApiClient.getClient().create(ApiInterface.class);

#call api (Normal)
Map<String, String> map = new HashMap<String, String>();
map.put("request_param_name", "1");
Call<ResponseBody> call= apiService.dashboard(AppSharedPreferences.getSharePreference(mContext).getAccessToken(), map);

#Response
  call.clone().enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

try {

if (response.isSuccessful()) {

if (response.body().getSuccess() == 1) {
Toast.makeText(mContext, response.body().getData().getMessage(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(mContext, response.body().getError().get(0), Toast.LENGTH_SHORT).show();
}
} else {
assert response.body() != null;
Toast.makeText(mContext, response.body().getError().get(0), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
}
});
}

#call api (Image with text)
@Multipart
@POST("users/edit_profile")
Call<ResponseBody> editProfile(@PartMap Map<String, RequestBody> fieldMap, @Part MultipartBody.Part image);

// creaet param
MultipartBody.Part body = null;
if (imageFile != null) {
RequestBody reqFile = RequestBody.create(MediaType.parse("multipart/form-data"), imageFile);
body = MultipartBody.Part.createFormData("image", imageFile.getName(), reqFile);
}

Map<String, RequestBody> map = new HashMap<>();
map.put(Constant.TAG_USER_ID, toRequestBody(user.user_id));


Call<ResponseBody> callApi = apiService.editProfile(map, body);
editProfileHttpUrl = callApi.request().url();
callApi.clone().enqueue(this);

public static RequestBody toRequestBody(String value) {
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), value);
return body;
}

#call api (only Image)
@Multipart
@POST("edit-profile")
Call<UserData> uploadProfile(@Header("Authorization") String auth, @Part MultipartBody.Part image);

Request
MultipartBody.Part body = null;
if (imageFile != null) {
RequestBody reqFile = RequestBody.create(MediaType.parse("multipart/form-data"), imageFile);
body = MultipartBody.Part.createFormData("profile_pic", imageFile.getName(), reqFile);
}
Call<UserData> callUploadProfile = apiService.uploadProfile(AppSharedPreferences.getSharePreference(mContext).getAccessToken(), body);

Monday, 3 February 2020

Location foregroud service android native

- This is a location update demo
- Frequently update location
- When the app in the background then starts the foreground s service to get the location.
- It even gets a location to continue if the app finished from the background.


Download Demo: https://drive.google.com/open?id=1Hghm--12etkZq-e1NV9R8O6_XygBBbKL

Monday, 20 January 2020

CashFree Payment gateway demo/Example


just comment or uncomment for Test and Production mode


Download demo here:

https://drive.google.com/open?id=1XdK3xhKf8Ro4oDNoVrzcVJ9TW5QRfnSy

Monday, 18 November 2019

This release is compatible with the google play 64-bit requirements / 64 bit support

 Build.gradle

Step 1 - import below the line

import com.android.build.OutputFile



Step 2 - add ndk Tag insie defaultConfig tag

defaultConfig {
      ------

    ndk {

            // config you want to support device

            abiFilters 'arm64-v8a', 'armeabi', 'armeabi-v7a', 'x86' , 'x86_64'

        }
}


Step 3 - add splits tag inside Android tag

android {

splits {

// Configures multiple APKs based on ABI.

        abi {

// Enables building multiple APKs per ABI.

            enable true


// By default all ABIs are included, so use reset() and include to specify that we only

// want APKs for x86, armeabi-v7a, and mips.

            reset()


// Specifies a list of ABIs that Gradle should create APKs for.

            include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"


// Specifies that we want to also generate a universal APK that includes all ABIs.

            universalApk true

        }

    }


// Map for the version code that gives each ABI a value.

    def abiCodes = ['x86': 1, 'x86_64': 2, 'armeabi-v7a': 3, 'arm64-v8a': 4]


// APKs for the same app that all have the same version information.

    android.applicationVariants.all { variant ->

// Assigns a different version code for each output APK.

        variant.outputs.each {

            output ->

                def abiName = output.getFilter(OutputFile.ABI)

                output.versionCodeOverride = abiCodes.get(abiName, 0) * 100000 + variant.versionCode

        }

    }

}


Step 4 - there are generate multiple apk, 
Upload apk : app-universal-release.apk

Thursday, 4 July 2019

Face detection and Pixelate programetically in android


Face detection using Firebase vision library.

Pixelate face using canvas.

Demo here: https://drive.google.com/open?id=1AwIAC1zi06gj-wrC_eahmiPXSEdsMPKQ


Face detection and pixelate without internet/offline

Run/install/debug Android applications over Wi-Fi ?

Open Teminal/cmd --------------- Below steps is for Android 10 or lower Step 1 - Connect the device via USB and make sure debugging is work...