小编mah*_*guy的帖子

Android通知仅显示状态栏上的图标

在我的应用程序中,我写了简单的通知功能,该方法只显示状态栏上的图标,我也想显示通知布局,但没有自动显示,我已经下拉Android状态栏,看到,

public static void createNotification(Context context, Class activity, String title, String subject, int count_unread_message) {

    Intent intent = new Intent(context, activity);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);

    Notification notify = new NotificationCompat.Builder(context)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentText(subject)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setNumber(count_unread_message)
            .setPriority(0)

            .setLights(Color.BLUE, 500, 500)
            .setContentIntent(pendingIntent)
            .build();

    notify.flags |= Notification.FLAG_AUTO_CANCEL;

    NOTIFICATIONMANAGER = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    NOTIFICATIONMANAGER.notify(159753456, notify);
}
Run Code Online (Sandbox Code Playgroud)

看来这个问题适用于Android 6及以上版本

android

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

我如何获得 mySql 列长度/值

我可以使用此命令获取列表信息,但不会返回 column Length/Values,我怎样才能得到它?

SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tableName' 
Run Code Online (Sandbox Code Playgroud)

mysql

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

Android只接受az和AZ之间的字符

我试图实现简单的逻辑只接受a-zA-Z编程之间的字符

一个简单的解决方案是

<EditText
    android:id="@+id/LanguageText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:digits="@string/app_lan" />
Run Code Online (Sandbox Code Playgroud)

在Strings.xml中:

<string name="app_lan">abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>
Run Code Online (Sandbox Code Playgroud)

但我想以编程方式实现它

username.addTextChangedListener(new TextWatcher() {
    public void afterTextChanged(Editable s) {
        if (s.toString().length() > 0) {
            /* if char is not between a-z and A-Z then return*/
            if ((int) s.toString().charAt(0) < 65 && (int) s.toString().charAt(0) > 90 || (int) s.toString().charAt(0) < 97 && (int) s.toString().charAt(0) > 122) {
                return;
            }else{
                /* Accept character */
            }
        }
    }
    public void beforeTextChanged(CharSequence s, int start, int count, …
Run Code Online (Sandbox Code Playgroud)

android android-edittext

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

Android 如何在线程上使用 Realm

在我的应用程序中,我读取保存在手机上的联系人,这可能需要很长时间,然后我将其放在Thread我正在使用的嵌套中Realm,但出现此错误:

Realm access from incorrect thread. 
Realm objects can only be accessed on the thread they were created.
Run Code Online (Sandbox Code Playgroud)

我的解决方案不能解决这个问题,例如:

new Handler().post(new Runnable() {
    @Override
    public void run() {
        realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
            }
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

或者

new Handler(getMainLooper()).post(new Runnable() {
    @Override
    public void run() {
        realm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
            }
        });            
    }
});
Run Code Online (Sandbox Code Playgroud)

在嵌套线程上,

java android realm

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

Android为多个Dagger2模块使用单个上下文

我是Dagger2在Android 上使用的新手.我创建一些类作为他们正在使用的Dagger模块context,我不能合并,组合或使用单个上下文用于他们需要的其他模块.我现在得到这个错误:

android.content.Context is bound multiple times
Run Code Online (Sandbox Code Playgroud)

SpModules:

@Module
public class SpModules {
    private Context context;

    public SpModules(Context context) {
        this.context = context;
    }

    @Provides // this can be non-scoped because anyway the same instance is always returned
    Context provideContext() {
        return this.context;
    }

    @Provides
    @Singleton
    SP provideSharePreferences(Context context) {
        return new SP(context); // use method-local Context
    }
}
Run Code Online (Sandbox Code Playgroud)

RealmModule:

@Module
public class RealmModule {
    private Context context;

    @Provides
    Context provideApplicationContext() {
        return AlachiqApplication.getInstance();
    } …
Run Code Online (Sandbox Code Playgroud)

android dependency-injection dagger-2

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

Nodejs mysql 获取正确的时间戳格式

我正在使用mysqljs,在得到结果后,sql我得到了不同的TimeStamp格式,如下所示:

created_at: Sat Jul 16 2016 23:52:54 GMT+0430 (IRDT)
Run Code Online (Sandbox Code Playgroud)

但它在 mysql 上是:

2016-07-16 23:52:54
Run Code Online (Sandbox Code Playgroud)

我想得到那个,而不是其他格式,我如何在 mysql 连接或 sql 命令上设置这种格式?

var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'a',
    database: 'signal'
});

connection.query(command, function (err, rows) {
    if (err) throw err;
    console.log(rows);
});
Run Code Online (Sandbox Code Playgroud)

javascript node.js

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

Android 检查设备 IMEI 是否有效

在我的应用程序中,我们使用设备imei并基于该设备返回一些结果。我找不到任何解决方案来验证手机 IMEI,用户可以使用一些模拟器,例如 Genymotion,我的应用程序必须检测到这一点,如果用户使用模拟器,我必须不将数据发布到服务器,我如何验证 IMEI?

这个解决方案PHP工作正常,但我找不到与 java for android 相同的解决方案

function is_luhn($n) {
    $str = '';
    foreach (str_split(strrev((string) $n)) as $i => $d) {
        $str .= $i %2 !== 0 ? $d * 2 : $d;
    }
    return array_sum(str_split($str)) % 10 === 0;
}
function is_imei($n){
    return is_luhn($n) && strlen($n) == 15;
} 
Run Code Online (Sandbox Code Playgroud)

java android

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

Android 在 API 级别 4 上从 cardview 中删除白色边框

我的 android 版本是 4.2,我试图从中删除白色边框和空格,但我的解决方案card_view:cardPreventCornerOverlap="false"来自xmlns:app="http://schemas.android.com/apk/res-auto"命名空间不能正常工作

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:elevation="0dp"
    card_view:cardPreventCornerOverlap="false">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/market_item_background">

        <ImageView
            android:id="@+id/market_thumbnail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:scaleType="centerCrop"/>

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

这是我使用的应用程序的一部分 CardView

在此处输入图片说明

android

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