我有一个带有操作按钮的自定义通知:
public class NotificationReceiver extends com.parse.ParsePushBroadcastReceiver {
@Override
public void onPushReceive(Context context, Intent intent) {
...
NotificationActivity notification = new NotificationActivity();
notification.createNotification(context, message, notificationId);
Log.i("tag", "Notification Received!");
}
Run Code Online (Sandbox Code Playgroud)
public class NotificationActivity {
public int notificationId;
public void createNotification(Context context, String message, String studentId, String notificationId){
this.notificationId = Integer.parseInt(notificationId);
// manager
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// notification
Notification.Builder mBuilder = new Notification.Builder(context);
mBuilder.setContentTitle("My Title");
mBuilder.setContentText(message);
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
mBuilder.setAutoCancel(true);
mBuilder.setStyle(new Notification.BigTextStyle()
.bigText(message));
// cancel intent
Intent cancelIntent = new Intent(context, CancelNotification.class);
Bundle …
Run Code Online (Sandbox Code Playgroud) 我正在提高应用程序的稳定性和性能,但现在我遇到了来自 Android Studio 的警告。请考虑以下 Adapter 类:
private class CoinsAdapter(private val fragment: CoinFragment, private val coins: List<Coin>): RecyclerView.Adapter<CoinsAdapter.ViewHolder>(), Filterable {
private val filter = ArrayList(coins)
override fun onCreateViewHolder(parent: ViewGroup, position: Int): ViewHolder {
val binding = ItemCoinBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val coin = filter[position]
holder.binding.coinImage.setImageResource(coin.image)
holder.binding.coinText.text = builder.toString()
}
override fun getItemCount() = filter.size
override fun getFilter() = object : Filter() {
override fun performFiltering(constraint: CharSequence): FilterResults {
if (constraint.length < 2) …
Run Code Online (Sandbox Code Playgroud) 让我们假设我有这个firebase JSON结构:
而且我需要得到所有具有"from"等于"this"的属性的问题.
我知道我可以使用Volley创建一个StringRequest并从我的questions.json中获取所有值.然后,在客户端,我可以迭代响应并删除那些没有正确属性的响应,但这只有在我有几个问题时才有效.如果我有数百万个问题,我需要重复数百万个问题.
有没有什么办法可以在我的请求上设置一个过滤器来获取具有我选择属性的问题?(例如:搜索questions.json,其中== this)
我正在尝试在我的应用程序上实施 Google 登录。
它工作正常,但是当我尝试登录时,我的 logcat 出现以下错误:
2018-10-04 14:55:14.784 16313-16313/? I/AppCompatDelegate:无法实例化自定义视图 inflater android.support.v7.app.AppCompatViewInflater。回到默认状态。java.lang.ClassNotFoundException: android.support.v7.app.AppCompatViewInflater at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:453) at java.lang.Class.forName (Class.java:378) at android.support.v7.app.AppCompatDelegateImpl.a(:com.google.android.gms@13280019@13.2.80 (040400-211705629):1) at android.support.v7.app .AppCompatDelegateImpl.onCreateView(:com.google.android.gms@13280019@13.2.80 (040400-211705629):1) 在 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772) 在 android.view. (LayoutInflater.java:
我正在使用新的 AndroidX 库,并且实现了以下依赖项:
implementation 'androidx.appcompat:appcompat:1.0.0'
Run Code Online (Sandbox Code Playgroud)
我还更改了gradle.properties以让 Android 知道我正在使用新的 AndroidX 库:
# Default properties
org.gradle.jvmargs=-Xmx1536m
# Android X properties
android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)
通过修改gradle.properties所有其他依赖项应该使用新的 AndroidX 库,对吗?为什么要尝试使用旧的 V7 库?我应该如何解决这个问题?
编辑
这是我的毕业证书:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig …
Run Code Online (Sandbox Code Playgroud) 在我的代码中,我有这个 if 语句:
if (categoryName == "SomeName1" || categoryName == "SomeName2" ||
categoryName == "SomeName3" || categoryName == "SomeName4" ||
categoryName == "SomeName5" || categoryName == "SomeName6") {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
我想知道如果我可以缩短这个。就像是:
if (categoryName == "SomeName1" and "SomeName2" and "SomeName3" ...) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在 Kotlin 中做这样的事情?
我使用 SafetyNet reCAPTCHA 已经有一段时间了。工作完美,但由于 SafetyNet 已弃用,我决定将集成迁移到 reCAPTCHA Enterprise。
SafetyNet reCAPTCHA 非常简单:
val recaptcha = SafetyNet.getClient(this).verifyWithRecaptcha(BuildConfig.RECAPTCHA_SITE)
recaptcha.addOnSuccessListener(this) { response ->
val token = response.tokenResult
// verify token with https://www.google.com/recaptcha/api/siteverify
}
Run Code Online (Sandbox Code Playgroud)
进行此 SafetyNet 调用时,我会收到一个验证码加载对话框,然后如果用户看起来像是机器人,则会出现带有图像的常见验证码。
现在,对于 reCAPTCHA Enterprise,我得到了完全不同的结果:
suspend fun validateUser(action: String) {
val recaptcha = Recaptcha.getClient(activity.application, BuildConfig.RECAPTCHA_SITE)
recaptcha.onSuccess { client ->
client.getUserToken(action)
}
}
private suspend fun RecaptchaClient.getUserToken(action: String) {
val execution = execute(RecaptchaAction.custom(action))
execution.onSuccess { token ->
// create assessment
}
}
Run Code Online (Sandbox Code Playgroud)
我可以获得客户端,并且可以获得令牌。现在,我需要创建一个评估来获取分数,但是当我调用execute (RecaptchaAction.custom(action))方法时,不应该出现验证码对话框或其他内容吗?reCAPTCHA Enterprise 只能作为隐形验证码使用吗?
我觉得我在文档中遗漏了一些东西,但我似乎真的无法理解这个新的 reCAPTCHA 在 Android …
我有一个名为“Car”的班级模型。如果我想创建一个新的“汽车”对象,我可以这样做:
Car car = new Car();
Run Code Online (Sandbox Code Playgroud)
但是现在,我让这个类实现了 Parcelable。创建“汽车”类的新对象的最佳方法是什么?
现在我这样做:
Car car = new Car("blue");
Run Code Online (Sandbox Code Playgroud)
我正在向我的模型类添加一个新的构造函数:
public class Car implements Parcelable {
public String color;
@Override
public int describeContents() { return 0; }
@Override
public void writeToParcel(Parcel dest, int flags) { dest.writeString(color); }
public static final Creator<Car> CREATOR = new Creator<Car>() {
public Car createFromParcel(Parcel in) { return new Car(in); }
public Car[] newArray(int size) { return new Car[size]; }
};
private Car(Parcel in) { color = in.readString(); }
public Car(String …
Run Code Online (Sandbox Code Playgroud)