modify targetSdkVersion to 31 and share
MODIFY
bither-android/AndroidManifest.xml
bither-android/AndroidManifest.xml
<activity
android:name="ChooseModeActivity"
android:screenOrientation="portrait"
+ android:exported="true"
android:theme="@style/BitherTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
android:name="net.bither.activity.hot.SelectAddressToSendActivity"
android:configChanges="orientation|keyboard|keyboardHidden"
android:screenOrientation="portrait"
+ android:exported="true"
android:theme="@style/BitherTransparentBgTheme"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>

MODIFY
bither-android/src/net/bither/activity/hot/HotActivity.java
bither-android/src/net/bither/activity/hot/HotActivity.java
@@ -151,6 +151,7 @@ public class HotActivity extends BaseFragmentActivity {
unregisterReceiver(txAndBlockBroadcastReceiver);
unregisterReceiver(addressIsLoadedReceiver);
unregisterReceiver(addressIsLoadingReceiver);
+ unregisterReceiver(peerConnectedChangeReceiver);
super.onDestroy();
BitherApplication.hotActivity = null;

MODIFY
bither-android/src/net/bither/activity/hot/MarketDetailActivity.java
bither-android/src/net/bither/activity/hot/MarketDetailActivity.java
@@ -63,6 +63,7 @@ import net.bither.util.ExchangeUtil;
import net.bither.util.FileUtil;
import net.bither.util.ImageManageUtil;
import net.bither.util.MarketUtil;
+import net.bither.util.ShareUtil;
import java.util.Date;
@@ -351,33 +352,7 @@ public class MarketDetailActivity extends SwipeRightActivity implements OnChecke
int width = bmpContent.getWidth();
int height = bmpContent.getHeight() + tvMarketName.getHeight() * 2;
Bitmap result = ImageManageUtil.getBitmapFromView(v, width, height);
- final Uri uri = FileUtil.saveShareImage(result);
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- if (dp != null && dp.isShowing()) {
- dp.setThread(null);
- dp.dismiss();
- }
- if (uri != null) {
- Intent intent = new Intent(android.content.Intent.ACTION_SEND);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(Intent.EXTRA_STREAM, uri);
- intent.setType("image/jpg");
- try {
- startActivity(intent);
- } catch (Exception e) {
- e.printStackTrace();
- DropdownMessage.showDropdownMessage(MarketDetailActivity.this,
- R.string.market_share_failed);
- }
- } else {
- DropdownMessage.showDropdownMessage(MarketDetailActivity.this,
- R.string.market_share_failed);
- }
- }
- });
+ ShareUtil.shareBitmap(MarketDetailActivity.this, result);
}
}

MODIFY
bither-android/src/net/bither/service/BlockchainService.java
bither-android/src/net/bither/service/BlockchainService.java
@@ -129,8 +129,12 @@ public class BlockchainService extends android.app.Service {
}
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context
.ALARM_SERVICE);
- final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
- new Intent(context, BlockchainService.class), 0);
+ final PendingIntent alarmIntent;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ alarmIntent = PendingIntent.getService(context, 0, new Intent(context, BlockchainService.class), PendingIntent.FLAG_IMMUTABLE|0);
+ } else {
+ alarmIntent = PendingIntent.getService(context, 0, new Intent(context, BlockchainService.class), 0);
+ }
alarmManager.cancel(alarmIntent);
final long now = System.currentTimeMillis();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)

MODIFY
bither-android/src/net/bither/ui/base/dialog/DialogFancyQrCode.java
bither-android/src/net/bither/ui/base/dialog/DialogFancyQrCode.java
@@ -37,6 +37,7 @@ import net.bither.ui.base.DropdownMessage;
import net.bither.util.FileUtil;
import net.bither.util.ImageFileUtil;
import net.bither.util.PermissionUtil;
+import net.bither.util.ShareUtil;
import net.bither.util.ThreadUtil;
import net.bither.util.UIUtil;
@@ -119,7 +120,7 @@ public class DialogFancyQrCode extends Dialog implements View.OnClickListener,
private void share() {
if (qrCode != null) {
- new ShareThread().start();
+ ShareUtil.shareBitmap(activity, qrCode);
}
}
@@ -145,29 +146,4 @@ public class DialogFancyQrCode extends Dialog implements View.OnClickListener,
}
}
- private class ShareThread extends Thread {
- @Override
- public void run() {
- final Uri uri = FileUtil.saveShareImage(qrCode);
- if (uri == null) {
- DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
- return;
- }
- ThreadUtil.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- Intent intent = new Intent(android.content.Intent.ACTION_SEND);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(Intent.EXTRA_STREAM, uri);
- intent.setType("image/jpg");
- try {
- getContext().startActivity(intent);
- } catch (Exception e) {
- e.printStackTrace();
- DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
- }
- }
- });
- }
- }
}

MODIFY
bither-android/src/net/bither/ui/base/dialog/DialogFragmentFancyQrCodePager.java
bither-android/src/net/bither/ui/base/dialog/DialogFragmentFancyQrCodePager.java
@@ -19,12 +19,10 @@ package net.bither.ui.base.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
-import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
-import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
@@ -50,11 +48,11 @@ import net.bither.R;
import net.bither.preference.AppSharedPreference;
import net.bither.qrcode.Qr;
import net.bither.ui.base.DropdownMessage;
-import net.bither.util.FileUtil;
import net.bither.util.ImageFileUtil;
import net.bither.util.ImageManageUtil;
import net.bither.util.LogUtil;
import net.bither.util.PermissionUtil;
+import net.bither.util.ShareUtil;
import net.bither.util.StringUtil;
import net.bither.util.ThreadUtil;
import net.bither.util.UIUtil;
@@ -169,7 +167,9 @@ public class DialogFragmentFancyQrCodePager extends DialogFragment implements Vi
}
private void share() {
- new ShareThread().start();
+ Bitmap bmp = getQrCode();
+ dismissInAnyThread();
+ ShareUtil.shareBitmap(activity, bmp);
}
private void save() {
@@ -257,39 +257,6 @@ public class DialogFragmentFancyQrCodePager extends DialogFragment implements Vi
}
}
- private class ShareThread extends Thread {
- @Override
- public void run() {
- Bitmap bmp = getQrCode();
- dismissInAnyThread();
- if (bmp == null) {
- LogUtil.w("QR", "share qr code null");
- DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
- return;
- }
- final Uri uri = FileUtil.saveShareImage(bmp);
- if (uri == null) {
- DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
- return;
- }
- ThreadUtil.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- Intent intent = new Intent(android.content.Intent.ACTION_SEND);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(Intent.EXTRA_STREAM, uri);
- intent.setType("image/jpg");
- try {
- activity.startActivity(intent);
- } catch (Exception e) {
- e.printStackTrace();
- DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
- }
- }
- });
- }
- }
-
public Bitmap getQrCode() {
Fragment f = getActiveFragment();
if (f == null) {

MODIFY
bither-android/src/net/bither/ui/base/dialog/DialogPrivateKeyQrCode.java
bither-android/src/net/bither/ui/base/dialog/DialogPrivateKeyQrCode.java
@@ -35,6 +35,7 @@ import net.bither.bitherj.qrcode.QRCodeUtil;
import net.bither.runnable.FancyQrCodeThread;
import net.bither.ui.base.DropdownMessage;
import net.bither.util.FileUtil;
+import net.bither.util.ShareUtil;
import net.bither.util.ThreadUtil;
import net.bither.util.UIUtil;
import net.bither.util.WalletUtils;
@@ -114,7 +115,7 @@ public class DialogPrivateKeyQrCode extends Dialog implements View.OnClickListen
private void share() {
if (qrCode != null) {
- new ShareThread().start();
+ ShareUtil.shareBitmap(activity, qrCode);
}
}
@@ -125,29 +126,4 @@ public class DialogPrivateKeyQrCode extends Dialog implements View.OnClickListen
ivQr.setImageBitmap(bmp);
}
- private class ShareThread extends Thread {
- @Override
- public void run() {
- final Uri uri = FileUtil.saveShareImage(qrCode);
- if (uri == null) {
- DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
- return;
- }
- ThreadUtil.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- Intent intent = new Intent(android.content.Intent.ACTION_SEND);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(Intent.EXTRA_STREAM, uri);
- intent.setType("image/jpg");
- try {
- getContext().startActivity(intent);
- } catch (Exception e) {
- e.printStackTrace();
- DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
- }
- }
- });
- }
- }
}

MODIFY
bither-android/src/net/bither/util/FileUtil.java
bither-android/src/net/bither/util/FileUtil.java
@@ -215,6 +215,13 @@ public class FileUtil {
return Uri.fromFile(jpg);
}
+ public static File saveShareImageFile(Bitmap bmp) {
+ File dir = getDiskDir(IMAGE_CACHE_DIR, true);
+ File jpg = new File(dir, IMAGE_SHARE_FILE_NAME);
+ NativeUtil.compressBitmap(bmp, 85, jpg.getAbsolutePath(), true);
+ return jpg;
+ }
+
public static File getExternalCacheDir(Context context) {
// if (SdkUtils.hasFroyo()) {
//

MODIFY
bither-android/src/net/bither/util/PermissionUtil.java
bither-android/src/net/bither/util/PermissionUtil.java
@@ -42,4 +42,16 @@ public class PermissionUtil {
return true;
}
+ public static boolean isGrantExternalRW(Activity activity, int requestCode) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (activity.checkSelfPermission(PERMISSION_WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
+ || activity.checkSelfPermission(PERMISSION_READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
+ || activity.checkSelfPermission(PERMISSION_CAMERA) != PackageManager.PERMISSION_GRANTED) {
+ activity.requestPermissions(new String[]{PERMISSION_WRITE_EXTERNAL_STORAGE, PERMISSION_READ_EXTERNAL_STORAGE, PERMISSION_CAMERA}, requestCode);
+ return false;
+ }
+ }
+ return true;
+ }
+
}

ADD
bither-android/src/net/bither/util/ShareUtil.java
+package net.bither.util;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Build;
+import android.provider.MediaStore;
+
+import net.bither.R;
+import net.bither.ui.base.DropdownMessage;
+import net.bither.ui.base.dialog.DialogProgress;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+public class ShareUtil {
+
+ static private DialogProgress progress;
+
+ public static boolean shareBitmap(final Activity activity, final Bitmap bitmap) {
+ if (bitmap == null) {
+ DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
+ return false;
+ }
+ showProgress(activity);
+ Intent intent = new Intent(android.content.Intent.ACTION_SEND);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ Uri uri;
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ File shearImageFile = FileUtil.saveShareImageFile(bitmap);
+ String imageUri = insertImageToSystem(activity, shearImageFile.getAbsolutePath());
+ if (imageUri == null) {
+ hideProgress();
+ DropdownMessage.showDropdownMessage(activity, R.string.permissions_no_grant);
+ return false;
+ }
+ uri = Uri.parse(imageUri);
+ } else {
+ uri = FileUtil.saveShareImage(bitmap);
+ }
+ intent.putExtra(Intent.EXTRA_STREAM, uri);
+ intent.setType("image/jpg");
+ try {
+ intent = Intent.createChooser(intent, activity.getResources().getString(R.string.market_share_button));
+ activity.startActivity(intent);
+ hideProgress();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ DropdownMessage.showDropdownMessage(activity, R.string.market_share_failed);
+ }
+ hideProgress();
+ return false;
+ }
+
+ public static String insertImageToSystem(Context context, String imagePath) {
+ String url = null;
+ if (PermissionUtil.isGrantExternalRW((Activity) context, 1000)) {
+ try {
+ url = MediaStore.Images.Media.insertImage(context.getContentResolver(), imagePath, "share.jpg", "bither_share");
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return url;
+ }
+
+ static private void showProgress(Activity activity) {
+ if (progress != null) {
+ return;
+ }
+ progress = new DialogProgress(activity, R.string.please_wait);
+ progress.show();
+ }
+
+ static private void hideProgress() {
+ if (progress != null) {
+ progress.dismiss();
+ progress = null;
+ }
+ }
+}

MODIFY
bither-android/src/net/bither/util/SystemUtil.java
bither-android/src/net/bither/util/SystemUtil.java
@@ -26,6 +26,7 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
+import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -78,8 +79,11 @@ public class SystemUtil {
builder.setContentText(contentText);
builder.setContentTitle(title);
- builder.setContentIntent(PendingIntent.getActivity(context, 0, intent,
- PendingIntent.FLAG_CANCEL_CURRENT));
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE|PendingIntent.FLAG_CANCEL_CURRENT));
+ } else {
+ builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
+ }
builder.setWhen(System.currentTimeMillis());
Notification notification = null;
@@ -114,8 +118,11 @@ public class SystemUtil {
builder.setContentText(contentText);
builder.setContentTitle(title);
- builder.setContentIntent(PendingIntent.getActivity(context, 0, intent,
- PendingIntent.FLAG_CANCEL_CURRENT));
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE|PendingIntent.FLAG_CANCEL_CURRENT));
+ } else {
+ builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
+ }
builder.setWhen(System.currentTimeMillis());
Notification notification = null;

MODIFY
bitherj
bitherj
-Subproject commit 053f77c26dc4d3c0ae107f5e8700aec7d608fc3f
+Subproject commit 44f3803ccec204d5cd2ed47e5965bdeeebda7060

MODIFY
build.gradle
build.gradle
@@ -26,11 +26,11 @@ project(':bitherj') {
subprojects {
android {
- compileSdkVersion 30
+ compileSdkVersion 31
defaultConfig {
minSdkVersion 14
- targetSdkVersion 30
+ targetSdkVersion 31
versionCode 208
versionName "2.0.8"
multiDexEnabled true

DELETE
gradle.properties
-## Project-wide Gradle settings.
-#
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-#
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-# Default value: -Xmx10248m -XX:MaxPermSize=256m
-# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
-#
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
-#Mon Jan 11 16:17:04 CST 2016
-systemProp.http.proxyHost=127.0.0.1
-systemProp.http.proxyPort=3127
-org.gradle.jvmargs=-Xmx2048M

modify targetSdkVersion to 31 and share