小编Sai*_*Sai的帖子

是否可以在通话期间播放音乐,以便合作伙伴可以听到它?Android的

我正在尝试制作和应用程序像Call Cheater(最初为Symbian OS开发)

是否可以在电话交谈中播放音乐,接收者和来电者应该听到相同的声音或音乐?

如果是,我该如何实现?

android phone-call android-mediaplayer

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

同一类Kotlin中的@Provides和@Binds方法

在dagger 2.11之后,我们可以使用@Binds注释并在这种情况下将我们的模块标记为抽象,这比具体更有效.

如果我的模块同时具有@Provides和@Binds方法,我有两个选择:

  1. 最简单的方法是将@Provides实例方法标记为静态.

  2. 如果有必要将它们保留为实例方法,则可以将模块拆分为两个,并将所有@Binds方法提取到抽象模块中.

第二个选项在Java和Kotlin中运行良好,但第一个选项在Java中工作正常,但我不知道如何在Kotlin中实现相同的功能.如果我将@Provides方法移动到Companion对象,它会抛出Error:(30, 1) error: @Provides methods can only be present within a @Module or @ProducerModule.怎么能在Kotlin做到这一点.

第二种选择:(工作)

ApplicationModule.kt

@Module(includes = [ApplicationModule.Declarations::class])
abstract class ApplicationModule {
    @Module
    internal interface Declarations {
        @Binds
        fun bindContext(application: Application): Context
    }

    @Provides
    @Singleton
    fun provideMvpStarterService(): MvpStarterService {
        return MvpStarterServiceFactory.makeStarterService()
    }
}
Run Code Online (Sandbox Code Playgroud)

第一种选择:(不工作)

ApplicationModule.kt

@Module
abstract class ApplicationModule {
    //expose Application as an injectable context
    @Binds
    internal abstract fun bindContext(application: Application): Context

    companion object {
        @JvmStatic
        @Provides
        @Singleton
        fun …
Run Code Online (Sandbox Code Playgroud)

kotlin dagger-2

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

如何在Android上暂停handler.postDelayed()计时器

如何handler.postDelayed()使用按钮暂停计时器.所以当我再次点击相同的按钮时,handler.postDelayed()计时器应该恢复.

handler.postDelayed(counterz, 60);
Run Code Online (Sandbox Code Playgroud)

android timer handler

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

如何以编程方式在Android中启用Lollipop中的FlashLight

Camera cam = Camera.open();     
Parameters p = cam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
Run Code Online (Sandbox Code Playgroud)

以上剂量对Lollipop无效,因为在Lollipop中不推荐使用Camera.我无法找到任何其他方式在Lollipop中以编程方式打开Flash.我怎样才能做到这一点.提前致谢.

android

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

如何访问视图insde菜单中的actionLayout

我有三个菜单项,包括相同的app:actionLayout文本视图,如何通过代码单独访问文本视图,并为所有三个文本视图设置不同的文本.

activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/item_tracks"
            app:actionLayout="@layout/menu_text_layout"
            android:icon="@drawable/ic_play_arrow"
            android:title="Tracks"/>
        <item
            android:id="@+id/item_repeat"
            app:actionLayout="@layout/menu_text_layout"
            android:icon="@drawable/ic_play_arrow"
            android:title="Repeat"/>
        <item
            android:id="@+id/item_timer"
            app:actionLayout="@layout/menu_text_layout"
            android:icon="@drawable/ic_play_arrow"
            android:title="Timer"/>
    </group>

    <item android:title="More">
        <menu>
            <item
                android:id="@+id/item_animation"
                app:showAsAction="always"
                android:icon="@drawable/ic_play_arrow"
                app:actionLayout="@layout/switch_layout"
                android:title="Animation"/>
            <item
                android:id="@+id/item_background"
                android:icon="@drawable/ic_play_arrow"
                android:title="Background Music"/>
        </menu>
    </item>

</menu>
Run Code Online (Sandbox Code Playgroud)

menu_text_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tool="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tool:background="@android:color/white"
    android:gravity="center_vertical">

    <TextView
        android:id="@+id/switchForActionBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:maxLength="10"
        android:ellipsize="marquee"
        android:fontFamily="sans-serif"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:background="@color/Color_600"
        android:textColor="@android:color/white"
        android:padding="2.5dp"
        android:text="Change Text"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-menu

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

在单个语句Kotlin中列出clear和addAll

在kotlin中是否有任何方法将以下两行替换为一行.我知道我可以创建一个扩展函数,但我很想知道它是否已经存在于kotlin中.有点像listOfChecklist.clearAndAddAll().

listOfChecklist.clear()
listOfChecklist.addAll(newList)
Run Code Online (Sandbox Code Playgroud)

这就是我现在手动使用扩展功能.但我希望有更好的解决方案.

fun <E> MutableCollection<E>.clearAndAddAll(replace: MutableSet<E>) {
    clear()
    addAll(replace)
}
Run Code Online (Sandbox Code Playgroud)

kotlin

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

isMinifyEnabled()已弃用.有什么选择?

我使用下面的代码显然根据产品风格自动生成pro guard映射文件.

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            applicationVariants.all { variant ->
                if (variant.getBuildType().isMinifyEnabled()) {
                    variant.assemble.doLast {
                        copy {
                            from variant.mappingFile
                            into "${rootDir}/proguardTools"
                            rename { String fileName ->
                                "mapping-${variant.name}.txt"
                            }
                        }
                    }
                }
            }

        }
    }
Run Code Online (Sandbox Code Playgroud)

将android studio升级到3.0之后,它会显示一条警告说isMinifyEnabled()已弃用,我无法找到任何解决方案或替代方案isMinifyEnabled().有任何帮助提前感谢吗?

在此输入图像描述

android gradle android-build android-gradle-plugin android-gradle-3.0

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

在ConstraintLayout Android中出现问题

我试图设计一个注册屏幕,使用ConstraintLayout除Z顺序之外的一切顺利.当用户点击注册时,我需要在所有内容之上显示FrameLayout,但它不起作用.请检查屏幕截图.

<ImageView
    android:id="@+id/background_image"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:scaleType="centerCrop"
    android:tint="#80000000"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<ImageView
    android:id="@+id/logo"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="32dp"
    android:layout_marginLeft="32dp"
    android:layout_marginRight="32dp"
    android:layout_marginStart="32dp"
    android:layout_marginTop="24dp"
    android:src="@drawable/logo"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="@+id/background_image"
    app:layout_constraintVertical_bias="0.049"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintRight_creator="1" />

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="7dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="7dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:fontFamily="sans-serif-light"
    android:text="There is More"
    android:textColor="@android:color/white"
    app:layout_constraintBottom_toTopOf="@+id/scrollView2"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="@+id/logo"
    app:layout_constraintTop_toTopOf="@+id/logo"
    app:layout_constraintVertical_bias="1.0"
    tools:ignore="HardcodedText" />

<ScrollView
    android:id="@+id/scrollView2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="32dp"
    android:layout_marginLeft="32dp"
    android:layout_marginRight="32dp"
    android:layout_marginStart="32dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/logo"
    app:layout_constraintVertical_bias="0.050000012">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/input_layout_first_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeEditTextLight"> …
Run Code Online (Sandbox Code Playgroud)

android

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

Android Studio 消耗大量内存

我有配备 16 GB 内存的 MacBook Pro 15。我只是在 AndroidStudio 中运行一个项目,它需要大约 6 GB 的 RAM,并使我的 MacBook 变慢。这太疯狂了,AndroidStudio 3.0 出现了严重错误。

请查看屏幕截图,它有两个 java 实例,在没有模拟器的情况下占用了近 3.5 GB 的 RAM。

这个问题有解决方案吗?我知道这个https://developer.android.com/studio/intro/studio-config.html#low_memory但我有 16 GB RAM 它应该可以顺利处理而无需调整。

出于某种原因,Apple 将 MacBook 的 RAM 容量限制为 16 GB,而 Android 消耗了其中的大部分,这让我感到沮丧,因为我无法升级愚蠢的 RAM 或修复 Android Studio 内存问题。

单个项目的AndroidStudio疯狂内存消耗

performance ram android android-studio android-studio-3.0

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

如何在Android上循环之间实现无间隙音频播放

我几乎尝试了所有方法,但在循环单个轨道之间无法实现无间隙音频播放.

我尝试过的步骤失败了:

  1. .mp3 .wav .ogg使用两者 setLooping(true)setOnCompletionListener方法但不同的音频文件格式不同.
  2. 创建两个媒体播放器并使用setOnCompletionListener相同的循环逐个循环 无法循环无间隙.
  3. 使用setNextMediaPlayer(nextmp)它工作,但它只合并两个不同或相同的音轨没有任何差距,并停止播放,但我不知道如何循环它永远.

任何1请帮助我,提前谢谢.

audio android android-layout android-mediaplayer

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