小编Sjh*_*son的帖子

适用于API 17和19的AlarmManager

我有以下代码,每小时都会调用我打算"报警接收器"来执行检查

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
    notificationIntent.addCategory("android.intent.category.DEFAULT");

    PendingIntent broadcast = PendingIntent.getBroadcast(context,100,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR,1);
    alarmManager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), broadcast);
Run Code Online (Sandbox Code Playgroud)

这适用于Android API 19+(Android 4.4)

但是,我想允许Android API 17(4.2)能够使用我的应用程序,因为不是每个人都可以在他们的手机上获得4.4

问题是API 17不支持的setExact

是否有一种方法可以调用被调用的Intent,这是由API 17+支持的,或者我必须以某种方式找出android运行的verison并执行一段代码或其他代码?

谢谢

api android

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

如何以编程方式在Alert对话框的android中截取屏幕截图

我已经看到了以下链接,它确实采用了最佳答案截图

不过,我要的是为应用程序采取的警告对话框中的截图,我显示给用户,上述解决方案,下面的代码只需要目前是什么警告对话框后面,因此没有良好的截图

这是在没有人通过提供的链接的情况下使用的代码

Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);

    try {
        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";

        // create bitmap screen capture
        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);

        File imageFile = new File(mPath);

        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();

        openScreenshot(imageFile);
    } catch (Throwable e) {
        // …
Run Code Online (Sandbox Code Playgroud)

android screenshot

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

Android - 比较两个日期

我想在我的应用程序中比较两个日期

第一个日期将是今天的日期.第二个日期将来自数据库

要保存第二个日期,我的代码如下; (使用明天约会以保持简单)

 Calendar calendar = Calendar.getInstance();
 calendar.add(Calendar.DAY_OF_YEAR, 1);
 Date tomorrow = calendar.getTime();
 DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");

 String tomorrowAsString = dateFormat.format(tomorrow);
Run Code Online (Sandbox Code Playgroud)

因此tomorrowAsString (10-Oct-2015)存储在我的数据库中的表中

在另一种形式中,我正在检索该日期并将其放入String中

String steepingDate = (c.getString(3));
Run Code Online (Sandbox Code Playgroud)

我想我需要将该字符串转换为日期格式,然后使用以下内容获取今天的日期;

Calendar calendar = Calendar.getInstance();
Date today = calendar.getTime();
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");

String todayAsString = dateFormat.format(today);
Run Code Online (Sandbox Code Playgroud)

这里是我卡住因为我不知道如何打开steepingDate进入Date,然后什么是比较字符串的实际办法,我已经试过网上找,但有,我已经尝试了许多不同的方式和迄今为止没有人工作过.我想知道两者中哪一个更重要

编辑:

我结合了一些答案并得出以下结论;

do {
      String steepingDate = (c.getString(3));
      SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
      Date steepingdate = formatter.parse(steepingDate);

      Calendar calendar = Calendar.getInstance();
      Date today = calendar.getTime(); …
Run Code Online (Sandbox Code Playgroud)

android date

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

& 导致 XML 代码错误的符号

我有以下 XML 代码在我的 Crm Dynamics 表单中过滤我的查找字段。过滤器在输入到帐户字段的数据之后使用。但是,帐户字段可以包含&符号,当它包含时,会发生错误,指出 XML 格式不正确。

有没有人有任何解决问题的方法?

function accountcontact()
{
    Xrm.Page.getControl("new_contactlookup").addPreSearch(function () { addcontactlookup(); });

    function addcontactlookup()
    {
        var accountID = Xrm.Page.getAttribute("new_companylookup");
        var AccountIDObj= accountID.getValue();

        if (AccountIDObj != null)
        {
            var fetchFilter1 = "<filter type='and'><condition attribute='parentcustomerid' uitype='" + AccountIDObj[0].entityType + "' operator='eq' value='" + AccountIDObj[0].id + "' uiname='" + AccountIDObj[0].name + "' /></filter>";
            Xrm.Page.getControl("new_contactlookup").addCustomFilter(fetchFilter1);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

xml filter dynamics-crm-2013

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

Android - 如何添加日期

我从SQLiteDatabase中检索了一个Date,并通过以下内容将其格式化为我想要的格式;

String steepingDate = (c.getString(3));
SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy");
Date steepingdate = formatter.parse(steepingDate);
Run Code Online (Sandbox Code Playgroud)

我现在想让用户选择将steepingdate中的任何日期增加一定的天数,用户可以输入

我知道你可以用;

Date today = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 10);
Run Code Online (Sandbox Code Playgroud)

例如,在今天的日期添加10天

但是你如何做到这一点,以便它使用steepingdate而不是今天的日期

谢谢

更新;

日历按我的意思工作,但我现在想将新数据保存到数据库中,完整代码如下;

String steepingDate = (c.getString(3));
SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yyyy");
Date steepingdate = formatter.parse(steepingDate);

Integer amountDays = Integer.parseInt(TSExtend.getText().toString());

Calendar ca = Calendar.getInstance();
ca.setTime(steepingdate);
ca.add(Calendar.DAY_OF_YEAR, amountDays);

DateFormat dateFormat = new SimpleDateFormat("dd/MMM/yyyy");
String newDate = dateFormat.format(ca);
Run Code Online (Sandbox Code Playgroud)

我收到了错误;

坏类:类java.util.GregorianCalendar

有任何想法吗?

android date

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

标签 统计

android ×4

date ×2

api ×1

dynamics-crm-2013 ×1

filter ×1

screenshot ×1

xml ×1