如何在加密共享首选项中使用密钥别名?下面是我的加密共享首选项
KeyGenParameterSpec spec = new KeyGenParameterSpec.Builder(
DEFAULT_MASTER_KEY_ALIAS,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.setKeySize(DEFAULT_AES_GCM_MASTER_KEY_SIZE)
.build();
MasterKey masterKey = new MasterKey.Builder(this)
.setKeyGenParameterSpec(spec)
.build();
SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(this,
this.getResources().getString(R.string.app_preferences),
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
);
Run Code Online (Sandbox Code Playgroud)
我在实现这个时遇到了以下异常,
W/AndroidKeysetManager: keyset not found, will generate a new one
java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_key_keyset__ does not exist
at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readPref(SharedPrefKeysetReader.java:71)
at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.readEncrypted(SharedPrefKeysetReader.java:89)
at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:105)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:311)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:287)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:238)
at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:155)
at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:120)
Run Code Online (Sandbox Code Playgroud)
我需要替换DEFAULT_MASTER_KEY_ALIAS为该框中提到的密钥别名吗?如果是,那么我该如何在不进行硬编码的情况下做到这一点?
我已替换DEFAULT_MASTER_KEY_ALIAS为模块下项目结构中提到的关键别名。出现以下异常。
java.lang.IllegalArgumentException: KeyGenParamSpec's key alias does not match …Run Code Online (Sandbox Code Playgroud) 我为 EditText 设置可绘制的权利,如下所示,
editText.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_clear_black_24dp), null);
Run Code Online (Sandbox Code Playgroud)
我正在 xml 中为 EditText 设置可绘制左侧。我想将其可见性设置为可见或隐藏。我如何以编程方式执行此操作。
我有用于搜索的 EditText。当开始打字时,我正在以编程方式设置清晰的图标。
清除图标将清除 EditText 中的文本。当单击没有文本的清晰图标时,我想关闭键盘并隐藏清晰图标。下面是我的代码,
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.setCursorVisible(true);
editText.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_clear_black_24dp), null);
}
});
editText.setOnTouchListener(new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
if(editText.getCompoundDrawables()[2]!=null){
if(event.getX() >= (editText.getRight()- editText.getLeft() - editText.getCompoundDrawables()[2].getBounds().width())) {
if(!editText.getText().toString().equals("")) {
editText.setText("");
}
else {
// getWindow().setSoftInputMode(
// WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
closeKeyboard();
editText.setCursorVisible(false);
}
}
}
}
return …Run Code Online (Sandbox Code Playgroud) 我已经创建了抬头通知。如下所示,
NotificationCompat.Builder notification = new NotificationCompat.Builder(this, channelId)
.setContentTitle("Message")
.setContentText("Recieved Successfully")
.setContentIntent(pendingIntent)
//.setColor(ContextCompat.getColor(this, R.color.green))
.setSmallIcon(R.drawable.notification_icon)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH);
manager.notify(m,notification.build());
Run Code Online (Sandbox Code Playgroud)
上面的代码放置在一个名为 NotificationService 的类中,该类扩展了 Service。
我可以使用下面的代码设置颜色,
setColor(ContextCompat.getColor(this, R.color.colorAccent))
Run Code Online (Sandbox Code Playgroud)
但是使用它只能设置唯一的颜色。
**我的目标不是那样。我想用它的原始颜色设置我的图标,就像在 Dominos 中一样。
在Android Manifest中添加了以下代码,
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
Run Code Online (Sandbox Code Playgroud)
当我收到推送通知时,我正在启动我的服务以显示如下所示的通知, startService(new Intent(this,NotificationService.class));
但是我收到了灰色的通知图标,而不是原始颜色。还搜索了很多网站和堆栈问题。但是关于这个问题的答案是我上面提到的在Android Manifest中放置通知图标的代码。尽管我遵循了答案,但无法将通知图标设置为多米诺骨牌。我没能找到哪里出错了。搜索了大部分发布的堆栈问题。但无法为我的问题找到合适的答案。

任何人请帮助我...
以下是我收到的通知。
如您所见,我的通知图标由两个文本组成。这两个包含两种不同的颜色。这就是我正在努力实现的目标。但我只得到灰色。设置颜色只会为 h 和 m 设置一种独特的颜色。我不想要那个。
这个没有解决办法吗??没有人做到这一点??
android push-notification firebase heads-up-notifications firebase-cloud-messaging
我已经用 SQLiteOpenHelper 替换了 import net.sqlcipher.database.SQLiteOpenHelper
为了将数据插入数据库并从中获取数据,我使用了
SQLiteDatabase db = this.getWritableDatabase("mypassword");
而不是下面
SQLiteDatabase db = this.getWritableDatabase();
下面是我的 oncreate 和 onUpgrade,
@Override
public void onCreate(net.sqlcipher.database.SQLiteDatabase db) {
db.execSQL(ARecords.CREATE_TABLE);
db.execSQL(BRecords.CREATE_TABLE);
}
@Override
public void onUpgrade(net.sqlcipher.database.SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + ARecords.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + BRecords.TABLE_NAME);
//Create tables again
onCreate(db);
}
Run Code Online (Sandbox Code Playgroud)
在主活动中,
SQLiteDatabase.loadLibs(this);
Run Code Online (Sandbox Code Playgroud)
下面是我的依赖项
implementation 'net.zetetic:android-database-sqlcipher:4.4.3'
implementation 'androidx.sqlite:sqlite:2.1.0'
Run Code Online (Sandbox Code Playgroud)
我正在使用 SQLCipher 来防止我的应用程序被攻击者访问存储在 /data/data/com.applicationname/ 目录中的数据
Root 设备可以访问 data/data/com.applicationname/ 目录的权限。那么使用 SQLCipher …
我正在 Activity 的 onCreate 中执行以下操作,
if(condition satisfied){
imageView.setImage(passing view to resize);
imageview.setVisibility(View.VISIBLE);
}
else
imageview.setVisibility(View.INVISIBLE);
Run Code Online (Sandbox Code Playgroud)
像下面这样调整大小,
Bitmap bmSource = BitmapFactory.decodeResource(context.getResources(), res);
Bitmap bmThumbnail;
bmThumbnail = getResizedBitmap(bmSource, getScreenWidth() / x, (getScreenWidth() / y));
Drawable drawable = new BitmapDrawable(context.getResources(), bmThumbnail);
b.setBackground(drawable);
Run Code Online (Sandbox Code Playgroud)
在这段代码中,我提到了一个视图。但在实际代码中,我有多个视图此活动(视为 A)用作以下三个,
以便我根据此更改 Activity。使用图像作为通话所需的扬声器、静音、录音等。
a) 对拨出电话的显示进行更改。
b) 一旦收到来自其他人的呼叫接受立即为呼叫连接屏幕进行屏幕更改
c) 屏幕更改完成后,将启动计时器以进行呼叫。
a) 为了显示来电屏幕,使用了不同的活动。
b) 一旦用户接听电话,然后移动到活动 A。
c) 所以在 Activity A 中,最初会做一些图像设置。一旦我得到了对呼叫连接屏幕的接受图像更改的响应。
这就是整个过程。现在来解释一下这个问题,
我已经提到,在这两种情况下,呼叫连接屏幕的更改都将在活动 A 中完成。在第一种情况下,因为已经在同一屏幕中的初始图像设置将先前加载,一旦得到响应,呼叫连接屏幕的更改将完成。计时器将启动。这里没问题。
问题是,在接听来电时,它会转到活动 A 和初始图像设置。一旦得到接受响应将改变屏幕调用连接的屏幕和计时器启动。在这里加载初始图像设置需要时间。因此,延迟一秒启动计时器导致 A 人和 B 人的时间不同
并非所有设备都会出现此问题。在 Android 版本 8 中,我遇到了这个问题,而不是在上面的版本中。 …
我想为 Voip 拨号器应用程序实现“android.telephony”库。因此,根据此https://developer.android.com/reference/android/telecom/ConnectionService我正在尝试注册 PhoneAccount。我正在做如下,
private void registerPhoneAcc(String calleeURI, String phoneNumber) {
TelecomManager telecomManager = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
telecomManager = (TelecomManager) getContext().getSystemService(Context.TELECOM_SERVICE);
}
ComponentName componentName = new ComponentName(getContext().getPackageName(), String.valueOf(MyConnectionService.class));
PhoneAccountHandle phoneAccountHandle = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
phoneAccountHandle = new PhoneAccountHandle(componentName,"App" );
PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, "Primary").setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER).build();
telecomManager.registerPhoneAccount(phoneAccount);
}
}
Run Code Online (Sandbox Code Playgroud)
<service android:name=".app.MyConnectionService"
android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
<intent-filter>
<action android:name="android.telecom.ConnectionService" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
尽管我已经包含了许可,但我遇到了以下异常
W/System.err: java.lang.SecurityException: PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission.
2021-02-03 13:58:39.259 24630-24630/com.ex.voip W/System.err: at android.os.Parcel.readException(Parcel.java:2013)
2021-02-03 …Run Code Online (Sandbox Code Playgroud) 我想在 RecyclerView 中实现展开和折叠,如 gif 中所述。通过粘贴并上下滑动。我在下面尝试过, /sf/answers/936685991/ 很好,但不是我所期望的。 我使用 RecyclerView 列出应用程序内的所有通知。如果有人有任何想法或经验,请与我分享。任何帮助将不胜感激。提前致谢。
在大多数网站中,能够找到实现左右滑动的方法,但不能实现上下滑动。我想实现向上和向下滑动,就像向左滑动和向右滑动一样。 在 gif 中,我没有使用箭头来展开和折叠,我只是上下滑动。我想在应用程序内的 recyclerview 中实现同样的目标。
卡在 Android Studio 中加载设备中。在 Stack Overflow 中发现以下问题但没有帮助,
我尝试过使缓存无效并重新启动,但没有解决。请任何机构帮助我解决这个问题。我的 Android Studio 版本是 4.1.1 提前致谢。
下面的答案解决了我的问题:
要通过 VoIP 拨打电话,用户需要先注册。所以注册是强制性的。我对注册过程有一些基本了解。用户向服务器发送 REGISTER 请求,其过期标头值为 30 秒。服务器收到用户的请求后,会发送带有过期标头值 120 秒的响应。用户需要在expire header时间段结束之前或60秒之前再次注册。注册完成后,注册服务器将在位置服务器中发送用户的 uri 和位置。因此用户的位置将出现在位置服务器中。如果位置服务器有用户的位置,那么为什么用户需要在时间段结束之前再次注册。而且用户只需要在该时间段之前重新注册一次还是多次?用户 ip 将在位置服务器中存在多长时间?
android ×8
encryption ×2
java ×2
voip ×2
database ×1
encrypted-shared-preference ×1
firebase ×1
performance ×1
sip ×1
telephony ×1
xml ×1