小编alo*_*loj的帖子

我的应用或其依赖项是否违反Android广告ID政策?

我刚从Google Play收到此消息,但我没有收集广告ID.

警告原因:违反Android广告ID政策的使用和开发者分发协议的第4.8节

Google Play要求开发者在应用请求或处理敏感用户或设备信息时提供有效的隐私权政策.我们发现您的应用会收集并传输Android广告ID,但需遵守隐私政策要求.

是否有可能我的任何依赖使用它?这是依赖项列表:

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.anko:anko-common:$anko_version"

implementation ("com.android.support:appcompat-v7:$android_support_version") {
    exclude group: 'com.android.support', module: 'animated-vector-drawable'
    exclude group: 'com.android.support', module: 'design'
}
implementation ("com.android.support:design:$android_support_version") {
    exclude group: 'com.android.support', module: 'animated-vector-drawable'
}
implementation ("com.android.support:cardview-v7:$android_support_version") {
    exclude group: 'com.android.support', module: 'animated-vector-drawable'
    exclude group: 'com.android.support', module: 'design'
}
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
implementation 'com.github.apl-devs:appintro:v4.2.3'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
    transitive = true
}
implementation 'com.firebase:firebase-jobdispatcher:0.7.0'
implementation ("com.google.firebase:firebase-firestore:$firestore_version") {
    exclude group: 'com.google.firebase', module: 'firebase-auth'
}
implementation ("com.google.firebase:firebase-auth:$firebase_version") {
    exclude group: 'com.google.firebase', module: 'firebase-firestore'
}
implementation ("com.google.firebase:firebase-storage:$firebase_version") { …
Run Code Online (Sandbox Code Playgroud)

android google-play google-advertising-id google-play-console

191
推荐指数
10
解决办法
4万
查看次数

将lambda存储在kotlin中的变量中

我开始使用kotlin开发Android,我有一个lambda问题.我有一个函数在我的视图中设置一个监听器,如下所示:

fun setListener(listener: () -> Unit) {
}
Run Code Online (Sandbox Code Playgroud)

问题是作为lambda传递的代码不会在setListener函数中执行,它将在我的代码的另一部分执行(特别是当选择一个微调器的项目时)所以我必须"保存"或"存储"将此lambda转换为变量/属性,以便我能够在需要时执行它.有什么想法怎么做?

编辑:我通过以下方式实现了:

private var listener: (() -> Unit)? = null

fun setListener(listener: () -> Unit) {
    this.listener = listener
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法呢?谢谢

lambda android kotlin

10
推荐指数
2
解决办法
5592
查看次数

在android中绘制三角形背景

我需要将布局背景绘制为三角形,就像您在图片中看到的那样.

在此输入图像描述

我找到了一个他们做类似事情的例子,但我不知道如何使它适应我的情况.这是一个例子

谁能帮我?最好.

android android-drawable

9
推荐指数
1
解决办法
9364
查看次数

Android单元测试中的模拟对象使用kotlin - any()给出null

我正在尝试测试我的课程,我需要模拟一个static课程.我的代码如下: -

    PowerMockito.mockStatic(ToolTipUtil::class.java)
    PowerMockito.`when`(ToolTipUtil.wasToolTipShown(any(Context::class.java), "")).thenReturn(true)
    val context = mock(Context::class.java)

    presenter.onResume(context)

    verify(view).setMenuButtonShown(eq(false))
Run Code Online (Sandbox Code Playgroud)

但在第二行它会抛出一个错误:

"java.lang.IllegalStateException: any(Context::class.java) must not be null"
Run Code Online (Sandbox Code Playgroud)

我尝试过mockito-kotlinbefriending-kotlin-and-mockito没有退出.你知道怎么解决吗?

android unit-testing mockito kotlin

9
推荐指数
3
解决办法
3753
查看次数

RemoteViewsService不执行,

我想用里面的列表做一个小部件,我必须实现一个扩展RemoteViewsService的类,但是这个类永远不会执行,我的代码如下:

MyWidgetProvider

public class MyWidgetProvider extends AppWidgetProvider {

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget);

    Intent updateIntent = new Intent(context, WidgetService.class);
    for (int appWidgetId : appWidgetIds) {
        updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        updateIntent.setData(Uri.parse(updateIntent.toUri(Intent.URI_INTENT_SCHEME)));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) 
            views.setRemoteAdapter(appWidgetId, updateIntent);
        else
            views.setRemoteAdapter(appWidgetId, R.id.events_list, updateIntent);

        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.events_list);         
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
Run Code Online (Sandbox Code Playgroud)

WidgetService

public class WidgetService extends RemoteViewsService {
    public RemoteViewsFactory onGetViewFactory(Intent intent) {
        return new WidgetFactory(getApplicationContext(), intent);
    }
}
Run Code Online (Sandbox Code Playgroud)

和清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)

android widget

7
推荐指数
1
解决办法
4550
查看次数

Android通知未显示超过3个操作

我想显示一个包含5个动作的通知,但是它会显示3个动作.这是我用来显示它的代码

Notification notification =
            new android.support.v7.app.NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!")
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action1, null, pendingIntent1).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action2, null, pendingIntent2).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action3, null, pendingIntent3).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action4, null, pendingIntent4).build())
                    .addAction(new NotificationCompat.Action.Builder(R.drawable.action5, null, pendingIntent5).build())
                    .setAutoCancel(false)
                    .build();

NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(MEETING_NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)

notifications android android-notifications

6
推荐指数
1
解决办法
2268
查看次数

应用程序终止后,广播接收器不接收

我创建了一个广播接收器来管理这些事件(ACTION_SCREEN_ON、ACTION_SCREEN_OFF 和 ACTION_USER_PRESENT)。我在我的主要活动中像这样注册我的广播接收器

IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);

mReceiver = new UnlockReceiver();


registerReceiver(mReceiver, filter);
Run Code Online (Sandbox Code Playgroud)

我的问题是 UnlockReceiver 在我的应用程序被终止后没有接收到(当我从应用程序选择器中滑动它时)。我有这个问题,因为这些广播不能在清单上声明我已经尝试使用服务和警报管理器解决它。我该如何解决?

android broadcastreceiver

5
推荐指数
1
解决办法
3160
查看次数

RemoteViewsService 未从通知中调用

我想在通知中显示 GridView,我正在使用 RemoteViews 来显示自定义布局。我的代码如下所示:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        showNotification();
    }

    private void showNotification(){

        RemoteViews rw = new RemoteViews(this.getPackageName(), R.layout.notification_layout);
        rw.setRemoteAdapter(R.id.grid_view, new Intent(this, AppService.class));
        rw.setImageViewResource(R.id.image, R.mipmap.ic_launcher);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Custom View")
                .setContent(rw);    
        ((NotificationManager)getSystemService(NOTIFICATION_SERVICE)).notify(1, builder.build());    

        //startService(new Intent(this, AppService.class));

    }

}
Run Code Online (Sandbox Code Playgroud)

notification_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:orientation="vertical"
    >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

<GridView
    android:id="@+id/grid_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="64dp"
    android:verticalSpacing="0dp"
    android:columnWidth="192dp"
    android:numColumns="auto_fit"
    />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

应用服务类

public class AppService …
Run Code Online (Sandbox Code Playgroud)

android gridview android-notifications remoteview android-remoteview

5
推荐指数
0
解决办法
340
查看次数

如何保护自己的服务器制作的http云功能?

我已经看到了一些关于如何保护经过身份验证的用户进行api调用的示例(针对Firebase的云功能的安全HTTP触发器,如何保护firebase云功能HTTP端点仅允许Firebase经过身份验证的用户?).但我的问题是我需要从我的服务器(我实现自定义令牌授权)中调用这些端点.有没有办法保护我服务器的电话?也许为它或其他什么产生一个令牌?

firebase firebase-authentication google-cloud-functions

5
推荐指数
0
解决办法
364
查看次数

Firebase 云函数停止工作 - event.data 未定义

我有一些云功能,但它们突然停止工作,现在我得到 event.data 未定义

exports.newMessageReceived = functions.database.ref('/messages/{pushId}')
 .onWrite((event) => {

    if (event.data.previous.exists() || !event.data.exists() ) {
        //Do nothing if data is edited or deleted
        console.log('Message edited or deleted - skip');
        return;
    }
   ...
}
Run Code Online (Sandbox Code Playgroud)

我得到

TypeError: Cannot read property 'previous' of undefined
Run Code Online (Sandbox Code Playgroud)

此处是这样定义的。firebase 云功能有什么变化吗?

javascript node.js firebase firebase-realtime-database google-cloud-functions

4
推荐指数
1
解决办法
2936
查看次数

java.lang.NoClassDefFoundError:无法初始化类 org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel

我正在尝试执行 Android 项目,但收到此错误。我在 Mac 上运行 M1、JDK 11.0.11 和 kotlin 1.4.21。

> Task :common:kaptGenerateStubsAppDebugKotlin FAILED
e: java.lang.NoClassDefFoundError: Could not initialize class org.jetbrains.kotlin.com.intellij.pom.java.LanguageLevel
Run Code Online (Sandbox Code Playgroud)

这是完整的日志https://pastebin.com/kzHuad70

android gradle kapt

4
推荐指数
1
解决办法
6149
查看次数

如何在Kotlin中模拟物体?

我想测试一个调用一个对象的类(java中的静态方法调用),但是我无法模拟这个对象以避免执行真正的方法.

object Foo {
    fun bar() {
        //Calls third party sdk here
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的选项,如Mockk,如何模拟Kotlin单例对象?并以与java相同的方式使用PowerMock,但没有成功.

使用PowerMockito的代码:

@RunWith(PowerMockRunner::class)
@PrepareForTest(IntentGenerator::class)
class EditProfilePresenterTest {

    @Test
    fun shouldCallIntentGenerator() {

        val intent = mock(Intent::class.java)

        PowerMockito.mockStatic(IntentGenerator::class.java)
        PowerMockito.`when`(IntentGenerator.newIntent(any())).thenReturn(intent) //newIntent method param is context

       presenter.onGoToProfile()

       verify(view).startActivity(eq(intent))        

    }
}
Run Code Online (Sandbox Code Playgroud)

有了这个代码,我得到了

java.lang.IllegalArgumentException:指定为非null的参数为null:方法com.sample.test.IntentGenerator $ Companion.newIntent,parameter context

any()方法来自mockito_kotlin.然后,如果我将一个模拟的上下文传递给newIntent方法,则看起来似乎是真正的方法.

android unit-testing mockito kotlin powermockito

3
推荐指数
1
解决办法
5833
查看次数

PowerMockito 给出 NoClassDefFoundError

我正在尝试使用 Mockito 和 PowerMockito 设置单元测试,但它抛出:

线程“main”中的异常 java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter

每当我尝试运行测试时。这些是我的依赖项:

testCompile 'org.mockito:mockito-core:2.8.9'
testCompile 'org.powermock:powermock-api-mockito2:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.7.4'
Run Code Online (Sandbox Code Playgroud)

有谁知道如何修理它?

java android unit-testing mockito powermockito

1
推荐指数
1
解决办法
9334
查看次数