# Conflicts:
#	src/notes/ui/NotesPreferenceActivity.java
pull/3/head
ranhao 4 months ago
commit 3805eef775

@ -0,0 +1,24 @@
package net.micode.notes;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
}

@ -64,21 +64,33 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
}
private void showNotification(int tickerId, String content) {
Notification notification = new Notification(R.drawable.notification, mContext
.getString(tickerId), System.currentTimeMillis());
notification.defaults = Notification.DEFAULT_LIGHTS;
notification.flags = Notification.FLAG_AUTO_CANCEL;
PendingIntent pendingIntent;
// 1. 创建通知构建器(替代旧构造函数)
Notification.Builder builder = new Notification.Builder(mContext)
.setSmallIcon(R.drawable.notification) // 替代旧的第一个参数
.setTicker(mContext.getString(tickerId)) // 替代旧的第二个参数
.setWhen(System.currentTimeMillis()) // 替代旧的第三个参数
.setDefaults(Notification.DEFAULT_LIGHTS) // 替代 notification.defaults
.setAutoCancel(true) // 替代 notification.flags = FLAG_AUTO_CANCEL
.setContentTitle(mContext.getString(R.string.app_name))
.setContentText(content);
// 2. 创建 PendingIntent
Intent intent;
if (tickerId != R.string.ticker_success) {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesPreferenceActivity.class), 0);
intent = new Intent(mContext, NotesPreferenceActivity.class);
} else {
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext,
NotesListActivity.class), 0);
intent = new Intent(mContext, NotesListActivity.class);
}
notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content,
pendingIntent);
// Android 12+ 需要 FLAG_IMMUTABLE 或 FLAG_MUTABLE
PendingIntent pendingIntent = PendingIntent.getActivity(
mContext, 0, intent, PendingIntent.FLAG_IMMUTABLE);
// 3. 设置意图
builder.setContentIntent(pendingIntent);
// 4. 构建并发送通知
Notification notification = builder.build();
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
}

@ -16,6 +16,7 @@
package net.micode.notes.ui;
import androidx.core.content.ContextCompat;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.ActionBar;
@ -70,6 +71,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
private Account[] mOriAccounts; // 原始账户列表(用于检测新添加的账户)
private boolean mHasAddedAccount; // 标记是否添加了新账户
// 在文件顶部添加这个 import
// import androidx.core.content.ContextCompat;
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
@ -82,15 +86,28 @@ public class NotesPreferenceActivity extends PreferenceActivity {
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
mReceiver = new GTaskReceiver(); // 创建广播接收器
IntentFilter filter = new IntentFilter();
<<<<<<< HEAD
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME); // 注册同步服务广播
registerReceiver(mReceiver, filter); // 注册广播接收器
=======
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
// ✅ 修复:兼容 Android 13+ 的广播注册方式(无需 if/else
ContextCompat.registerReceiver(
this,
mReceiver,
filter,
null,
null,
ContextCompat.RECEIVER_NOT_EXPORTED // 内部广播,更安全
);
>>>>>>> ce8801278409c0c99db42eb507f3f732202b6249
mOriAccounts = null;
// 添加设置界面的头部视图
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
getListView().addHeaderView(header, null, true);
}
@Override
protected void onResume() {
super.onResume();

Loading…
Cancel
Save