小编mat*_*ous的帖子

Android:蓝牙无法获取端口号

我在我的应用程序中使用蓝牙时遇到了问题.似乎在创建28 BluetoothSocket/ 之后BluetoothServerSockets,所有端口都被占用.插座不需要同时打开,因为蓝牙已启用,它只有28个插座.

可以使用Android示例中提供的BluetoothChat示例重现此问题.只需打开和关闭应用程序15次(该应用程序每次创建2个插槽).在第15次,它将崩溃并将继续崩溃,直到您禁用然后重新启用蓝牙:

12-06 18:43:58.177: E/BluetoothSocket(18530): bindListen, fail to get port number, exception: java.io.IOException: read failed, socket might closed, read ret: -1
12-06 18:43:58.193: E/BluetoothChatService(18530): Socket Type: Insecurelisten() failed
12-06 18:43:58.193: E/BluetoothChatService(18530): java.io.IOException: Error: -1
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:1035)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.bluetooth.BluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord(BluetoothAdapter.java:982)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.example.android.BluetoothChat.BluetoothChatService$AcceptThread.<init>(BluetoothChatService.java:280)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.example.android.BluetoothChat.BluetoothChatService.start(BluetoothChatService.java:119)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at com.example.android.BluetoothChat.BluetoothChat.onResume(BluetoothChat.java:131)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at android.app.Activity.performResume(Activity.java:5182)
12-06 18:43:58.193: E/BluetoothChatService(18530):  at …
Run Code Online (Sandbox Code Playgroud)

android bluetooth

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

从Google地图中的"分享此地点"获取坐标

查看Google地图中任何位置的详细信息时,可以选择"共享此地点".通过在清单中将我的应用程序添加到我的应用程序,我已成功将自己添加到接收器列表中:

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

与此捆绑包一起传递的附加内容是Intent.EXTRA_SUBJECT和Intent.EXTRA_TEXT.我在以下活动中检索了这些额外内容:

Bundle extras = getIntent().getExtras();
Run Code Online (Sandbox Code Playgroud)

Intent.EXTRA_SUBJECT包含一个带有该位置标题的字符串.Intent.EXTRA_TEXT包含一个字符串,其中包含该位置的详细地址和移动地图URL.

是否可以从"共享此地点"操作中检索该位置的GPS坐标(经度和纬度)?

android

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

Android:ContentObserver selfChange

在ContentObserver类中,方法onChange传递一个布尔值selfChange,定义为:"如果更新是由对正在观察的光标的提交调用引起的,则为true."

更新光标以使selfChange设置为true的正确方法是什么?我当前的代码根本没有引用光标进行更新,因此selfChange总是为false.

ContentValues values = new ContentValues();
values.put("date", date.getTime());
getContentResolver().update(URI, values, "_id = " + id, null);
Run Code Online (Sandbox Code Playgroud)

android

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

onContextItemSelected不会被调用

我创建了一个简单的应用程序,只显示一个AlertDialog,列表中有四个项目.我注册了一个上下文菜单.当我长按其中一个项目时,我会看到上下文菜单.然后我从上下文菜单中选择一个项目,但onContextItemSelected永远不会被调用.有帮助吗?谢谢.

test.java:

package com.cerulean.tech.creations.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class test extends Activity {

    private String[] files;
    AlertDialog alert;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        files = new String[4];
    }

    public void selectScheme(View v) {
        files[0] = "<New Scheme>";
        files[1] = "test1";
        files[2] = "test2";
        files[3] = "test3";
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setItems(files, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int item) { …
Run Code Online (Sandbox Code Playgroud)

android contextmenu android-alertdialog

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