Whatsapp business implemented with EMI amount
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
|
||||
<queries>
|
||||
<package android:name="com.whatsapp" />
|
||||
<package android:name="com.whatsapp.w4b" />
|
||||
</queries>
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
|
||||
<application
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Base64;
|
||||
|
||||
import android.os.Looper;
|
||||
@@ -39,6 +40,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -71,7 +73,7 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule {
|
||||
@Override
|
||||
public void onActivityResult(Activity activity, int i, int i1, @Nullable Intent intent) {
|
||||
if(i1 != RESULT_CANCELED) {
|
||||
if (i == WHATSAPP_SHARE_REQUEST_CODE) {
|
||||
if (i == WHATSAPP_SHARE_REQUEST_CODE && (imageFile!=null)) {
|
||||
new File(Uri.fromFile(imageFile).getPath()).delete();
|
||||
}
|
||||
}
|
||||
@@ -180,50 +182,87 @@ public class DeviceUtilsModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWhatsAppInstalled() {
|
||||
public ArrayList<String> isWhatsAppInstalled() {
|
||||
PackageManager packageManager = RNContext.getPackageManager();
|
||||
List<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_META_DATA);
|
||||
ArrayList<String> appsInstalled = new ArrayList<String>();
|
||||
|
||||
for (PackageInfo packageInfo : packages) {
|
||||
String packageName = packageInfo.packageName;
|
||||
if(packageName.equals("com.whatsapp")){
|
||||
return true;
|
||||
if(packageName.equals("com.whatsapp") || packageName.equals("com.whatsapp.w4b")){
|
||||
appsInstalled.add(packageName);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return appsInstalled;
|
||||
}
|
||||
|
||||
public Intent getWhatsappShareIntent(String message, String imageUrl, String mimeType, String packageName) {
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
|
||||
|
||||
if (imageUrl.equals("")) {
|
||||
sendIntent.setType("text/plain");
|
||||
sendIntent.setPackage(packageName);
|
||||
} else {
|
||||
sendIntent.setType(mimeType);
|
||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
imageFile = convertBase64ToFile(getReactApplicationContext(), imageUrl);
|
||||
Uri fileUri = FileProvider.getUriForFile(getReactApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", new File(
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
|
||||
imageFile.getName()
|
||||
)
|
||||
);
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||
sendIntent.setPackage(packageName);
|
||||
}
|
||||
|
||||
return sendIntent;
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void sendFeedbackToWhatsapp(String message, String imageUrl, String mimeType, Promise promise) {
|
||||
try{
|
||||
if(!isWhatsAppInstalled()){
|
||||
ArrayList<String> appsInstalled = isWhatsAppInstalled();
|
||||
int numberOfAppsInstalled = appsInstalled.size();
|
||||
|
||||
if(numberOfAppsInstalled == 0){
|
||||
promise.reject("errorCode", "1");
|
||||
return;
|
||||
}
|
||||
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
|
||||
|
||||
if(imageUrl.equals("")) {
|
||||
sendIntent.setType("text/plain");
|
||||
sendIntent.setPackage("com.whatsapp");
|
||||
getCurrentActivity().startActivity(sendIntent);
|
||||
} else {
|
||||
sendIntent.setType(mimeType);
|
||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
imageFile = convertBase64ToFile(getReactApplicationContext(), imageUrl);
|
||||
Uri fileUri = FileProvider.getUriForFile(getReactApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", new File(
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
|
||||
imageFile.getName()
|
||||
)
|
||||
);
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||
sendIntent.setPackage("com.whatsapp");
|
||||
getCurrentActivity().startActivityForResult(sendIntent, WHATSAPP_SHARE_REQUEST_CODE);
|
||||
else if(numberOfAppsInstalled == 1) {
|
||||
String packageName = appsInstalled.get(0);
|
||||
Intent sendIntent = getWhatsappShareIntent(message, imageUrl, mimeType, packageName);
|
||||
if(getCurrentActivity()!=null) {
|
||||
getCurrentActivity().startActivityForResult(sendIntent, WHATSAPP_SHARE_REQUEST_CODE);
|
||||
}
|
||||
promise.resolve(true);
|
||||
return;
|
||||
}
|
||||
|
||||
else {
|
||||
String packageName1 = appsInstalled.get(0);
|
||||
String packageName2 = appsInstalled.get(1);
|
||||
//Firing two intents, one for WhatsApp, another for WhatsApp business
|
||||
Intent sendIntent1 = getWhatsappShareIntent(message, imageUrl, mimeType, packageName1);
|
||||
Intent sendIntent2 = getWhatsappShareIntent(message, imageUrl, mimeType, packageName2);
|
||||
ArrayList<Intent> appIntents = new ArrayList<>();
|
||||
appIntents.add(sendIntent1);
|
||||
appIntents.add(sendIntent2);
|
||||
|
||||
Intent defaultIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||
defaultIntent.setType("text/plain");
|
||||
defaultIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Sharing to WhatsApp");
|
||||
|
||||
Intent chooserIntent = Intent.createChooser(defaultIntent, "Share via");
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, appIntents.toArray(new Parcelable[appIntents.size()]));
|
||||
if (getCurrentActivity() != null) {
|
||||
getCurrentActivity().startActivityForResult(chooserIntent, WHATSAPP_SHARE_REQUEST_CODE);
|
||||
}
|
||||
promise.resolve(true);
|
||||
return;
|
||||
}
|
||||
promise.resolve(true);
|
||||
return;
|
||||
|
||||
} catch (Error e){
|
||||
promise.reject("errorCode","2");
|
||||
|
||||
@@ -368,10 +368,3 @@ export function getDistanceFromLatLonInKm(
|
||||
const distance = 2 * Math.atan2(Math.sqrt(intermediateResult), Math.sqrt(1 - intermediateResult));
|
||||
return EARTH_RADIUS * distance;
|
||||
}
|
||||
|
||||
export function insertCommasinAmount(amount: number | undefined) {
|
||||
const reversedAmount = amount?.toString().split('').reverse().join('');
|
||||
const groups = reversedAmount?.match(/.{1,3}/g);
|
||||
const result = groups?.join(',').split('').reverse().join('');
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user