修复了Android高版本崩溃问题,优化了细节操作。

This commit is contained in:
muqing 2023-10-22 13:46:52 +08:00
parent e9986ef8c3
commit e84f9aaa85
20 changed files with 129 additions and 216 deletions

View File

@ -12,7 +12,7 @@ android {
//noinspection OldTargetApi
targetSdk 31
versionCode 1
versionName "1.5.0"
versionName "1.5.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
@ -36,22 +36,6 @@ android {
outputFileName = "Cloud_music-${variant.name}-v${variant.versionName}.apk"
}
}
signingConfigs {
signConfig {
storeFile file('F:/muqing.jks')
//
storePassword 'muqing153'
//
keyAlias 'muqing'
//
keyPassword 'muqing153'
//
}
release {
v1SigningEnabled true // true使用 false不适用
v2SigningEnabled true
}
}
kotlinOptions {
jvmTarget = '1.8'
}

View File

@ -1090,9 +1090,6 @@ open class LyricViewX : EaseView, LyricViewXInterface {
}
companion object {
private const val TAG = "LyricViewX"
// 时间线持续时间
private const val TIMELINE_KEEP_TIME = 3 * DateUtils.SECOND_IN_MILLIS
}

View File

@ -1,20 +0,0 @@
package com.dirror.lyricviewx
import android.animation.TimeInterpolator
import kotlin.math.pow
/**
* Smooth 插值器
* @author Moriafly
*/
@Deprecated("过时")
class SmoothInterpolator: TimeInterpolator {
override fun getInterpolation(input: Float): Float {
val a = 1.11571230005336
val b = -1.99852071205059
val c = 0.272428743837376
val d = -1.15835562067601E-05
return ((a - d) / (1.0 + (input.toDouble() / c).pow(b)) + d).toFloat()
}
}

View File

@ -13,6 +13,7 @@ import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.muqingbfq.api.url;
import com.muqingbfq.fragment.bfq_db;
import com.muqingbfq.fragment.mp3;
import java.io.IOException;
@ -22,9 +23,9 @@ import java.util.TimerTask;
public class MediaPlayer extends android.media.MediaPlayer {
public MediaPlayer() {
this.setOnCompletionListener(mediaPlayer -> {
if (!home.db.view.isShown()) {
/* if (!home.db.view.isShown()) {
home.db.view.setVisibility(View.VISIBLE);
}
}*/
int i = bfqkz.getmti(bfqkz.ms);
bfqkz.xm = bfqkz.list.get(i);
new Thread() {
@ -50,7 +51,7 @@ public class MediaPlayer extends android.media.MediaPlayer {
if (bfq.kg != null) {
bfq.kg.setImageResource(R.drawable.zt);
}
home.db.txa.setImageResource(R.drawable.zt);
bfq_db.txa.setImageResource(R.drawable.zt);
bfqkz.updateNotification();
}
}
@ -88,7 +89,7 @@ public class MediaPlayer extends android.media.MediaPlayer {
if (bfq.kg != null) {
bfq.kg.setImageResource(R.drawable.bf);
}
home.db.txa.setImageResource(R.drawable.bf);
bfq_db.txa.setImageResource(R.drawable.bf);
bfqkz.updateNotification();
}
@ -99,7 +100,7 @@ public class MediaPlayer extends android.media.MediaPlayer {
prepare();
bfqkz.tdt_max = getDuration();
bfqkz.tdt_wz = getCurrentPosition();
Glide.with(main.context)
Glide.with(home.appCompatActivity)
.asBitmap()
.load(bfqkz.xm.picurl)
.addListener(new RequestListener<Bitmap>() {
@ -109,7 +110,6 @@ public class MediaPlayer extends android.media.MediaPlayer {
bfqkz.notify.setBitmap(null);
return false;
}
@Override
public boolean onResourceReady(@NonNull Bitmap bitmap, @NonNull Object model, Target<Bitmap> target,
@NonNull DataSource dataSource, boolean isFirstResource) {
@ -128,8 +128,8 @@ public class MediaPlayer extends android.media.MediaPlayer {
bfq.zz.setText(bfqkz.xm.zz);
bfq_an.islike(bfq.like.getContext());
}
home.db.name.setText(bfqkz.xm.name);
home.db.zz.setText(bfqkz.xm.zz);
bfq_db.name.setText(bfqkz.xm.name);
bfq_db.zz.setText(bfqkz.xm.zz);
if (mp3.lbspq != null) {
mp3.lbspq.notifyDataSetChanged();
}

View File

@ -92,7 +92,7 @@ public class url extends Thread {
return new JSONObject(hq).getJSONArray("songs").getJSONObject(0)
.getJSONObject("al").getString("picUrl");
} catch (Exception e) {
yc.start(main.context, e);
yc.start(e);
}
return null;
}

View File

@ -71,6 +71,7 @@ public class bfq extends AppCompatActivity {
}
inflate = inflater.inflate(R.layout.fragment_bfq, container, false);
lrcView = inflate.findViewById(R.id.gc);
lrcView.setVisibility(View.GONE);
Toolbar toolbar = inflate.findViewById(R.id.toolbar);
name = inflate.findViewById(R.id.name);
zz = inflate.findViewById(R.id.zz);
@ -119,10 +120,6 @@ public class bfq extends AppCompatActivity {
lrcView.setVisibility(View.GONE);
kp.setVisibility(View.VISIBLE);
});
inflate.findViewById(R.id.layout).setOnClickListener(view1 -> {
lrcView.setVisibility(View.GONE);
kp.setVisibility(View.VISIBLE);
});
inflate.findViewById(R.id.bfq_list_mp3).
setOnClickListener(view1 -> com.muqingbfq.fragment.bflb_db.start(context));

View File

@ -4,8 +4,8 @@ import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -29,6 +29,7 @@ public class bfqkz extends MediaBrowserServiceCompat {
public static boolean like_bool;
@SuppressLint("StaticFieldLeak")
public static com.muqingbfq.mq.NotificationManagerCompat notify;
public static int getmti(int s) {
int i = bfqkz.list.indexOf(xm);
if (s == 1) {
@ -57,54 +58,55 @@ public class bfqkz extends MediaBrowserServiceCompat {
gj.sc("bfqkz mp3(String id) :" + e);
}
}
public static MediaSessionCompat mSession;
public static MediaMetadataCompat build;
public static PlaybackStateCompat playback;
@Override
public void onCreate() {
super.onCreate();
mSession = new MediaSessionCompat(this, "MusicService");
playback=new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_NONE,0,1.0f)
.build();
mSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPlay() {
mt.start();
// 处理播放音乐逻辑
}
@Override
public void onPause() {
// 处理暂停音乐逻辑
mt.pause();
if(playback.getState() == PlaybackStateCompat.STATE_PLAYING){
playback = new PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PAUSED,0,1.0f)
.build();
mSession.setPlaybackState(playback);
}
}
@Override
public void onSkipToNext() {
// 处理切换到下一首音乐逻辑
}
@Override
public void onSkipToPrevious() {
// 处理切换到上一首音乐逻辑
}
});//设置回调
/* Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(this, start.class));//用ComponentName得到class对象
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// 关键的一步设置启动模式两种情况
MediaButtonReceiver.handleIntent(mSession,intent);*/
MediaMetadataCompat build = new MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "歌手名称")
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, "专辑名称")
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, "歌曲名称")
build = new MediaMetadataCompat.Builder()
.build();
mSession.setMetadata(build);
mSession.setPlaybackState(playback);
mSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
mSession.setActive(true);
setSessionToken(mSession.getSessionToken());
notify = new com.muqingbfq.mq.NotificationManagerCompat(this);
/* ;
// 激活MediaSessionCompat
*/
// 初始化通知栏
}
@Nullable

View File

@ -26,15 +26,6 @@ public class bflb_db extends BottomSheetDialog {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_bflb_db);
// 获取对话框窗口
/* Window window = getWindow();
if (window != null) {
// 设置高度为默认值例如500dp
WindowManager.LayoutParams params = window.getAttributes();
params.height =
window.setAttributes(params);
}*/
// 设置默认弹出高度和最大上拉高度为 400dp
int height = main.g - main.g / 2 / 2;
getBehavior().setPeekHeight(height);
getBehavior().setMaxHeight(height);

View File

@ -1,5 +1,6 @@
package com.muqingbfq.fragment;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -24,9 +25,11 @@ import java.lang.reflect.Type;
import java.util.List;
public class bfq_db extends Fragment {
public View view;
public TextView name, zz;
public ImageView txa;
@SuppressLint("StaticFieldLeak")
public static View view;
public static TextView name, zz;
public static ImageView txa;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,

View File

@ -11,9 +11,11 @@ import android.widget.Toast;
import com.muqingbfq.R;
import com.muqingbfq.activity_about_software;
import com.muqingbfq.home;
import com.muqingbfq.login.user_logs;
import com.muqingbfq.login.user_message;
import com.muqingbfq.mq.gj;
import com.muqingbfq.mq.wl;
public class sz {
@ -69,6 +71,9 @@ public class sz {
} else if (id == R.id.f) {
context.startActivity(new Intent(context, activity_about_software.class));
// 关于软件
} else if (id == R.id.g) {
new com.muqingbfq.login.visitor();
home.appCompatActivity.finish();
}
}
}

View File

@ -5,7 +5,6 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.v4.media.MediaBrowserCompat;
@ -28,10 +27,8 @@ import com.muqingbfq.fragment.bfq_db;
import com.muqingbfq.mq.gj;
public class home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
@SuppressLint("StaticFieldLeak")
public static Toolbar toolbar;
public Toolbar toolbar;
public static AppCompatActivity appCompatActivity;
@SuppressLint("CommitTransaction")
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -57,21 +54,10 @@ public class home extends AppCompatActivity implements NavigationView.OnNavigati
item.setTitle(spannableString);
}
new com.muqingbfq.fragment.sz(this, chb.getHeaderView(0));
db = new bfq_db();
getSupportFragmentManager().beginTransaction()
.add(R.id.bfq_db, db).commit();
.add(R.id.bfq_db, new bfq_db()).commit();
mediaBrowser = new MediaBrowserCompat(this,
new ComponentName(this, bfqkz.class), connectionCallbacks, null);
mediaBrowser.connect();
} catch (Exception e) {
gj.sc(e);
}
}
private MediaBrowserCompat mediaBrowser;
private final MediaBrowserCompat.ConnectionCallback connectionCallbacks =
new MediaBrowserCompat.ConnectionCallback() {
new ComponentName(this, bfqkz.class), new MediaBrowserCompat.ConnectionCallback() {
@Override
public void onConnected() {
// 连接成功后执行的操作
@ -97,10 +83,14 @@ public class home extends AppCompatActivity implements NavigationView.OnNavigati
// 连接失败时执行的操作
// gj.ts(home.this,"shibai");
}
};
}, null);
mediaBrowser.connect();
} catch (Exception e) {
gj.sc(e);
}
}
@SuppressLint("StaticFieldLeak")
public static bfq_db db;
MediaBrowserCompat mediaBrowser;
@Override
protected void onPause() {
@ -117,24 +107,8 @@ public class home extends AppCompatActivity implements NavigationView.OnNavigati
@Override
protected void onDestroy() {
super.onDestroy();
mediaBrowser.disconnect();
// mediaBrowser.disconnect();
}
@Override
public void onResume() {
super.onResume();
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
@Override
public void onStop() {
super.onStop();
// (see "stay in sync with the MediaSession")
if (MediaControllerCompat.getMediaController(home.this) != null) {
// MediaControllerCompat.getMediaController(home.this).unregisterCallback(controllerCallback);
}
mediaBrowser.disconnect();
}
private long time;
@Override

View File

@ -7,13 +7,10 @@ import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Looper;
import com.muqingbfq.mq.MyExceptionHandler;
import com.muqingbfq.mq.wj;
import com.muqingbfq.mq.wl;
public class main extends Application {
@SuppressLint("StaticFieldLeak")
public static Context context;
public static Handler handler = new Handler(Looper.getMainLooper());
public static String api = "http://139.196.224.229:3000";
public static String http = "http://139.196.224.229/muqing";
@ -27,7 +24,6 @@ public class main extends Application {
@Override
public void onCreate() {
super.onCreate();
context = this;
new wj(this);
sp = getSharedPreferences("Set_up", MODE_PRIVATE);
edit = sp.edit();
@ -61,6 +57,5 @@ public class main extends Application {
edit.commit();
}
// 创建全局异常处理器实例 设置全局异常处理器
Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(this));
}
}

View File

@ -1,32 +0,0 @@
package com.muqingbfq.mq;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import com.muqingbfq.yc;
public class MyExceptionHandler implements Thread.UncaughtExceptionHandler {
public static Throwable throwable;
private Context mContext;
public MyExceptionHandler(Context context) {
mContext = context;
}
@Override
public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) {
// 将异常信息打印到日志中
MyExceptionHandler.throwable = throwable;
String TAG = "MyExceptionHandler";
Log.e(TAG, "UncaughtException: ", throwable);
// 在这里执行生成错误报告的逻辑例如将错误信息保存到文件或发送给服务器
// 可以使用第三方库如ACRABugsnag等或者自行实现错误报告的处理逻辑
// 生成错误报告的逻辑
// 发送 Intent 重启应用
yc.start(mContext, throwable);
// 这里可以进行一些其他的操作例如记录错误日志弹出错误提示框等
// 终止程序
// android.os.Process.killProcess(android.os.Process.myPid());
// System.exit(0);
}
}

View File

@ -15,6 +15,7 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import androidx.core.app.ActivityCompat;
@ -24,7 +25,11 @@ import androidx.media.session.MediaButtonReceiver;
import com.muqingbfq.MyButtonClickReceiver;
import com.muqingbfq.R;
import com.muqingbfq.bfq;
import com.muqingbfq.bfq_an;
import com.muqingbfq.bfqkz;
import com.muqingbfq.fragment.bfq_db;
import com.muqingbfq.fragment.mp3;
import com.muqingbfq.home;
import com.muqingbfq.start;
import com.muqingbfq.yc;
@ -49,25 +54,21 @@ public class NotificationManagerCompat {
}
}
// 适配12.0及以上
int flag;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flag = PendingIntent.FLAG_IMMUTABLE;
} else {
flag = PendingIntent.FLAG_UPDATE_CURRENT;
}
// 设置启动的程序如果存在则找出否则新的启动
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(context, start.class));//用ComponentName得到class对象
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// 关键的一步设置启动模式两种情况
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, flag);
pendingIntent_kg = pendingIntent(context, new Intent(context, MyButtonClickReceiver.class).
PendingIntent pendingIntent = getActivity(context, intent);
// PendingIntent.getActivity(context, 0, intent, flag);
Intent my = new Intent(context, MyButtonClickReceiver.class);
pendingIntent_kg = getBroadcast(context, my.
setAction("kg"));
pendingIntent_syq = pendingIntent(context, new Intent(context, MyButtonClickReceiver.class).
pendingIntent_syq = getBroadcast(context, my.
setAction("syq"));
pendingIntent_xyq = pendingIntent(context, new Intent(context, MyButtonClickReceiver.class).
pendingIntent_xyq = getBroadcast(context, my.
setAction("xyq"));
// 取消操作的PendingIntent
// 取消操作的PendingIntent
@ -79,7 +80,7 @@ public class NotificationManagerCompat {
.setMediaSession(bfqkz.mSession.getSessionToken())
.setShowCancelButton(true)
.setCancelButtonIntent(cancelIntent);
//
notificationBuilder = getNotificationBuilder(context)
.setSmallIcon(R.drawable.icon)
.setContentTitle(name).setContentText(zz)
@ -124,7 +125,7 @@ public class NotificationManagerCompat {
notificationManager.notify(1, notificationBuilder.build());
}
@SuppressLint({"MissingPermission", "RestrictedApi"})
@SuppressLint({"MissingPermission", "RestrictedApi", "NotifyDataSetChanged"})
public void setBitmap(Bitmap bitmap) {
bfq.bitmap = bitmap;
if (bitmap == null) {
@ -140,6 +141,7 @@ public class NotificationManagerCompat {
if (bfq.tx != null) {
bfq.tx.setImageBitmap(bitmap);
}
}
private NotificationCompat.Builder getNotificationBuilder(Context context) {
@ -153,12 +155,29 @@ public class NotificationManagerCompat {
}
@SuppressLint("UnspecifiedImmutableFlag")
private PendingIntent pendingIntent(Context context, Intent intent) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
private PendingIntent getBroadcast(Context context, Intent intent) {
int flag;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flag = PendingIntent.FLAG_IMMUTABLE;
} else {
flag = PendingIntent.FLAG_UPDATE_CURRENT;
}
return PendingIntent.getBroadcast(context, 0, intent, flag);
/* if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
} else {
return PendingIntent.getBroadcast(context, 0, intent, 0);
}*/
}
@SuppressLint("UnspecifiedImmutableFlag")
private PendingIntent getActivity(Context context, Intent intent) {
int flag;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
flag = PendingIntent.FLAG_IMMUTABLE;
} else {
flag = PendingIntent.FLAG_UPDATE_CURRENT;
}
return PendingIntent.getActivity(context, 0, intent, flag);
}
}

View File

@ -66,7 +66,7 @@ public class gj {
}
}
} catch (SocketException e) {
yc.start(main.context, e);
yc.start(e);
}
return false; // 默认为流量网络
}

View File

@ -149,7 +149,6 @@ public class start extends AppCompatActivity {
}
private void startApp() {
SharedPreferences theme = getSharedPreferences("theme", MODE_PRIVATE);
@SuppressLint("CommitPrefEdits") SharedPreferences.Editor edit = theme.edit();
int i = theme.getInt("theme", AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);

View File

@ -24,7 +24,7 @@ public class yc extends AppCompatActivity {
}
public static void start(Object e) {
start(main.context, e);
start(home.appCompatActivity, e);
}
public static void start(Context context, Object e) {

View File

@ -19,11 +19,10 @@
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/Playlist">
android:layout_height="wrap_content">
</androidx.appcompat.widget.Toolbar>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/hdct"
android:id="@+id/gd"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
@ -34,7 +33,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.navigation.NavigationView
android:id="@+id/chb"
android:layout_width="match_parent"
@ -45,5 +43,4 @@
app:menu="@menu/sz"
tools:ignore="VisualLintBounds" />
</androidx.drawerlayout.widget.DrawerLayout>
</RelativeLayout>

View File

@ -22,8 +22,8 @@
<ImageView
android:id="@+id/img_logo"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="10dp"
android:src="@drawable/icon" />

View File

@ -33,27 +33,17 @@
android:text="@string/zz" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
<RelativeLayout
android:id="@+id/layout"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.dirror.lyricviewx.LyricViewX
android:id="@+id/gc"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:lrcCurrentTextColor="@color/text"
app:lrcNormalTextSize="16sp"
app:lrcPadding="16dp"
app:lrcTextSize="20sp"
app:lrcLabel="@string/app_name"
app:lrcTimelineTextColor="@color/text_tm"
tools:ignore="MissingConstraints" />
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/kp1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
android:gravity="center"
android:layout_weight="1">
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -67,7 +57,19 @@
android:src="@drawable/icon" />
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</RelativeLayout>
<com.dirror.lyricviewx.LyricViewX
android:id="@+id/gc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:lrcCurrentTextColor="@color/text"
app:lrcLabel="@string/app_name"
app:lrcNormalTextSize="16sp"
app:lrcPadding="16dp"
app:lrcTextSize="20sp"
app:lrcTimelineTextColor="@color/text_tm"
tools:ignore="MissingConstraints" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"