小编Sou*_*der的帖子

以编程方式发送短信而无需打开消息应用

到目前为止,我使用以下代码通过我的应用程序发送短信到另一部手机.

Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + srcNumber)); 
                    intent.putExtra( "sms_body", message ); 
                    startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

但是,这会打开本机消息传递应用程序,从而将我的应用程序活动置于后台.是否可以直接发送短信而无需打开本机消息应用程序?如果有,怎么样?

android android-activity

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

如何创建元组数组?

我知道要在C#中创建一个元组,我们使用以下格式:

Tuple <int,int>from = new Tuple<int,int>(50,350);
Tuple <int,int>to = new Tuple<int,int>(50,650);
Run Code Online (Sandbox Code Playgroud)

其中每个元组是一个坐标对.我想创建一个阵列使用的元组多个坐标对.有人可以帮我解决这个问题吗?

编辑:这是我到目前为止尝试过的.我希望它只是这种数组格式.

 Tuple<int, int>[] coords = new Tuple<int,int>({50,350},{50,650},{450,650});
Run Code Online (Sandbox Code Playgroud)

编译抱怨有问题..请告诉我它是什么?

c#

15
推荐指数
4
解决办法
3万
查看次数

绕过Android中的Google TTS Engine初始化延迟

我尝试在手机中触发特定事件时播放TextToSpeech对象.

但是,我遇到了大多数手机上安装的默认Google TTS引擎的问题.截至目前,我正在初始化TextToSpeech对象后立即播放一些文本,并在语音完成后立即关闭资源,如下面的代码所示:

public class VoiceGenerator {
private Context context = null;

private static TextToSpeech voice = null;

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


public void voiceInit(String text)
{
    try {
        if (voice == null) {

            new Thread(new Runnable() {
                @Override
                public void run() {
                    voice = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
                        @Override
                        public void onInit(final int status) {
                            try {
                                if (status != TextToSpeech.ERROR) {
                                    voice.setLanguage(Locale.US);
                                    Log.d("VoiceTTS", "TTS being initialized");
                                    HashMap p = new HashMap<String, …
Run Code Online (Sandbox Code Playgroud)

android android-service google-text-to-speech

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

如何在Android上创建.docx文件和.xlsx文件

我有一个非常简单的问题:如何在Android上创建.docx.xlsx文件.在有人将此标记为重复之前,请允许我告诉您,我已经尝试使用Apache POI创建它们,并且在这些问题中描述了我的尝试:

使用Apache POI创建.xlsx文件时的java.lang.NoClassDefFoundError

使用poi-ooxml jar文件创建.docx文件

但是,如这些链接中所述,我收到java.lang.verify错误.这些是我最终导入到参考库中的jar文件:

  • dom4j的-1.6.1.jar

  • POI-3.10-FINAL-20140208.jar

  • POI-OOXML-3.10-FINAL-20140208.jar

  • STAX的API-1.0.1.jar

  • XMLBeans的-2.3.0.jar

  • POI-OOXML-模式-3.10-FINAL-20140208.jar

  • 公地编解码器1.5.jar

  • 共享记录-1.1.jar

  • 基于JUnit 4.11.jar

  • log4j的-1.2.13.jar

但现在根本没有编译,并在控制台上说

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most …
Run Code Online (Sandbox Code Playgroud)

java eclipse excel android apache-poi

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

如何禁用/重新启用接收通知时发生的振动?

我在收到通知时为特定功能定义了自定义振动.

但是,当手机屏幕关闭时,自定义振动会伴随默认通知振动.

我尝试将手机置于静音模式,并以编程方式将其从静音模式中删除,并尝试使用部分唤醒锁,怀疑当CPU关闭时,也会抛出默认振动,但这两种方法似乎都不起作用.

我还尝试将默认音频和振动静音并在完成接收通知的任务后恢复它,但这只会有助于屏蔽默认通知声音,而不是默认振动.

//Trying to mute the notification sound and vibration
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
 //Restoring the defaults
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, defaultNotifVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
Run Code Online (Sandbox Code Playgroud)

请让我知道如何以编程方式禁用/启用默认通知振动.

android android-notifications android-vibration

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

局部变量和函数在C中可以使用相同的名称吗?

假设我有一个单一的,我有一个.c文件局部变量的一个.我可以在该c文件中有一个具有相同名称函数吗?

编辑:如果没有,为什么?

从概念上讲,局部变量存储在堆栈中,函数存储在内存的文本部分中.所以应该没问题吧?

当我尝试这个时,编译器给出了错误.我想知道这是特定于编译器还是实际上是一个错误.

c

9
推荐指数
4
解决办法
8541
查看次数

如何在"请勿打扰"设置中的"优先级应用程序通知"下查找允许的应用程序?

我正在尝试以编程方式找出特殊情况下绕过"请勿打扰"设置的应用程序.

在此输入图像描述

到目前为止,我使用以下代码检查手机是否设置为"请勿打扰"模式:

public static boolean isDnDModeEnabled(Context context)
{
    if(Build.VERSION.SDK_INT <23)
        return false;

    try {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        int filterValue = notificationManager.getCurrentInterruptionFilter();
        switch(filterValue)
        {
            case NotificationManager.INTERRUPTION_FILTER_ALL : Log.d("DND","Interruption filter all");
                break;
            case NotificationManager.INTERRUPTION_FILTER_ALARMS : Log.d("DND","Interruption filter alarms");
                break;
            case NotificationManager.INTERRUPTION_FILTER_PRIORITY : Log.d("DND","Interruption filter priority");
                break;
            case NotificationManager.INTERRUPTION_FILTER_UNKNOWN : Log.d("DND","Interruption filter unknown");
                break;
            case NotificationManager.INTERRUPTION_FILTER_NONE : Log.d("DND","Interruption filter none");
                break;

        }
        if(filterValue == NotificationManager.INTERRUPTION_FILTER_ALL)
            return false;
        else if(filterValue == NotificationManager.INTERRUPTION_FILTER_PRIORITY)
        {
            //Logic based on which apps are allowed as priority …
Run Code Online (Sandbox Code Playgroud)

android android-notifications

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

在Android中设置Crouton消息的持续时间

我已经开始使用Crouton消息而不是Toast消息,因为我可以配置持续时间.有没有什么方法可以继续显示crouton消息,直到特定事件,而不是以明确单位指定时间?

android crouton

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

Camera API无法在KITKAT上运行

我有一个非常奇怪的问题.以下代码用于在按钮单击时拍照.它适用于Jelly Bean手机,但不适用于Kitkat:

MainActivity.java:

package com.example.takepic;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends Activity {
  private final static String DEBUG_TAG = "MakePhotoActivity";
  private Camera camera;
  private Button capture = null;
  private int cameraId = 0;

  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  capture = (Button)findViewById(R.id.captureBack);
  capture.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
         camera.startPreview(); //After this, nothing gets …
Run Code Online (Sandbox Code Playgroud)

android android-camera android-camera-intent

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

如何在android中以编程方式使用HFP-bluetooth连接到远程手机

有没有办法在免提配置文件(HFP)模式下以编程方式配对和连接到远程设备?

到目前为止,我只能通过代码以正常方式连接到远程设备.我需要在HFP配置文件模式下连接到远程设备.

java android bluetooth bluetooth-sco android-bluetooth

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