小编Jha*_*Das的帖子

来电呼叫听众在几个小时后睡觉

在过去的几周里,我面临着Android中的电话管理器API的问题 - 基于监听器开始录制的呼入监听器以及结束呼叫停止录制(流程正常工作)

ISSUE
我现在面临的问题是,在一些手机,它正在所有的时间,但在一些手机,电话经理的广播听众停止后几个小时的工作.经过一些研究,我找到了一个使用唤醒锁来防止CPU睡眠的解决方案,我尝试了这个但是徒劳无功.

   @Override
public void onReceive(Context context, Intent intent) {
//We listen to two intents.  The new outgoing call only tells us of an 
 //outgoing  call.  We use it to get the number.
    roPlantPrefs = RoPlantPrefs.getInstance(context);
    databaseHelper = new DatabaseHelper(context);
     //lastState = roPlantPrefs.getLastState();

    if (roPlantPrefs.getLogin()) {


        if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
            savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
        } else {

            roPlantPrefs = RoPlantPrefs.getInstance(context);
 //            if (!roPlantPrefs.getIsOnCall()) {

            String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
            String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

            int state = 0;
            if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) …
Run Code Online (Sandbox Code Playgroud)

android android-wake-lock wakelock telephonymanager

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

RecyclerView:检测到不一致。无效的项目位置 - 为什么?

我们的 QA 检测到一个错误:发生了以下与 RecyclerView 相关的崩溃:`

java.lang.IndexOutOfBoundsException:检测到不一致。无效的项目位置 2(offset:2).state:3

一个残酷的解决方法可能是在异常发生时捕获异常并从头开始重新创建 RecyclverView 实例,以避免留下损坏的状态。

但是,如果可能的话,我想更好地理解这个问题(也许从源头上解决它),而不是掩盖它。

该错误很容易重现滚动继续快速创建此崩溃,但它发生时是致命的。

我的工作代码是:

public class MoviesGridRecyclerViewDataAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

public static final int VIEW_ITEM = 1;
public static final int VIEW_PROG = -1;
private static final int FADE_DURATION = 500;
int pastVisiblesItems, visibleItemCount, totalItemCount;
private List<VideoEntity> dataList;
private FragmentActivity activity;
private int visibleThreshold = 1;
//private int lastVisibleItem, totalItemCount;
//private boolean loading = false;
private OnLoadMoreListener onLoadMoreListener;
private RecyclerView.OnScrollListener recyclerciewScrollListener;
private RecyclerView recyclerView;
private boolean followLargeItemOnDataRender;
private boolean loading = …
Run Code Online (Sandbox Code Playgroud)

java android indexoutofboundsexception android-recyclerview

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

Android 4.4 从 CardView 中移除阴影

我试图从 Cardview 中删除阴影。
我在 android v4.4.2 上使用了 android support v7 Cardview

我的布局外观:

<android.support.v7.widget.CardView
    android:id="@+id/cardContainer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    card_view:cardBackgroundColor="@color/transparent"
    card_view:cardCornerRadius="0dp"
    card_view:cardElevation="0dp"
    card_view:cardPreventCornerOverlap="false"
    card_view:contentPadding="0dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/include_profile_header" />

        <include layout="@layout/include_profile_footer" />

    </RelativeLayout>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

如您所见,我使用了:

  card_view:cardElevation="0dp" 
Run Code Online (Sandbox Code Playgroud)

到目前为止尝试过:

android:background="@null"  
Run Code Online (Sandbox Code Playgroud)

但是您仍然可以在图像中看到我附加了显示的顶部阴影。

CardView 阴影

layout android android-layout android-support-library

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

Intent.ACTION_GET_CONTENT打开图片和pdf

我正在尝试打开最近的窗口,其中只有图像和pdf可选

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
Run Code Online (Sandbox Code Playgroud)

但在这我只能选择图像如何我也可以添加PDF

android android-intent

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

Android 中的弹跳动画

我想创建如下所示的动画;

动画弹跳

我使用了以下代码:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/bounce_interpolator" >

<scale
    android:duration="10000"
    android:fromXScale="1"
    android:fromYScale="0.5"
  />


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

但没能锻炼出来!任何帮助都将不胜感激。

谢谢

android android-animation

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

以编程方式在6.0中更改屏幕亮度

我正在开发一个以编程方式更改屏幕亮度的Android应用程序.我有一个适用于5.1.1的设置亮度方法,但是当我在6.0上运行应用程序时,它会出错并关闭应用程序.请帮忙.

以下是我的方法:

 public void setBrightness(View view,int brightness){

    //Just a loop for checking whether the brightness changes
     if(brightness <46)
        brightness = 255;
    else if(brightness >150)
        brightness=45;
    ContentResolver cResolver = this.getApplicationContext().getContentResolver();
    Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);

}

public void setDisplay(View view)
{
    ContentResolver  cResolver = getContentResolver();

    Window window = getWindow();
    int brightness=0;
    try
    {        Settings.System.putInt(cResolver,Settings.System.SCREEN_BRIGHTNESS_MODE
                                   Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
                   brightness = Settings.System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS);
        System.out.println("Current Brightness level " + brightness);
    }
    catch (Exception e)
    {
                   Log.e("Error", "Cannot access system brightness");
        e.printStackTrace();
    }
    setBrightness(view,brightness);
}
Run Code Online (Sandbox Code Playgroud)

android screen-brightness android-6.0-marshmallow

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