小编Emm*_*aux的帖子

如何在运行时检查权限而不抛出SecurityException?

我设计了一个可以从SD获取/设置资源的函数,如果没有从sd中找到,则将其从Asset中取出,如果可能的话将资产写回SD.
如果SD已安装且可访问,则此函数可通过方法调用进行检查...

boolean bSDisAvalaible = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
Run Code Online (Sandbox Code Playgroud)

我设计的函数可以从一个app(项目)到另一个app(使用或不使用android.permission.WRITE_EXTERNAL_STORAGE)使用

然后我想检查当前应用程序是否具有此特定权限而不使用SecurityException.

它是否存在一种在运行时查询当前定义的权限的"好方法"?

security permissions android runtime

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

super()之前和之后代码的区别

请查看下面的示例代码

@Override
protected void onPause() {
    ...some code here...
    super.onPause();
}
Run Code Online (Sandbox Code Playgroud)

@Override
protected void onPause() {
    super.onPause();
    ...some code here...
}
Run Code Online (Sandbox Code Playgroud)

当我询问代码差异时,我并不是指执行流程,这是明显的.

那么这些代码之间的真正区别是什么?建议何时 super()通话使用您的代码,以及何时 super()通话使用您的代码?我想有些情况确实很重要.

java oop android

45
推荐指数
3
解决办法
7843
查看次数

Android如何在屏幕上显示通知

我一直致力于推送通知,我能够实现它并在状态栏上显示它,我面临的问题是我想显示它,即使手机是锁定的,在它所说的锁定屏幕下("拖动解锁"),我已经看过这样的通知,但无法找到任何示例.

示例: 就像您收到未接来电一样,它会在屏幕上的锁定按钮下显示.

码:

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon_launcher;
CharSequence tickerText = "MyApplication";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.defaults |= Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS;;
CharSequence contentTitle = this.title;
CharSequence contentText = this.message;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTICE_ID, notification);
Run Code Online (Sandbox Code Playgroud)

notifications android lockscreen

28
推荐指数
3
解决办法
8万
查看次数

Android模拟器的VPN连接失败

我是Android开发的新手.我正在尝试从我的Android应用加入现有的VPN.我想在我的应用程序中集成VPN; 我的应用程序然后应该查询远程数据库.

我得到了一些代码并试图用它来创建VPN.它模拟Android手机上的内置VPN管理器.代码编译并启动管理器但是当我尝试在所有配置之后进行连接时,与VPN的连接不成功.该协议是PPTP.VPN存在并已经过测试.

我尝试从具有相同设置的Android手机连接,并且它成功了.

我想也许我以错误的方式传递参数.我已经为下面的vpn部分编了代码.网址不是实际的,但格式相同.

任何帮助,以确定我做错了什么将不胜感激.此外,如果有一种方法,我可以直接从我的应用程序调用VPN管理器.

非常感谢您的帮助,


final Button button1 = (Button)findViewById(R.id.button1);
final Button button2 = (Button)findViewById(R.id.button2);
final Button button3 = (Button)findViewById(R.id.button3);


    button1.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
            startActivity(new Intent("android.net.vpn.SETTINGS"));
        }
    });

    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            URL url = null;
            try {
                String registrationUrl = String.format("daffy.zune.org");
                url = new URL(registrationUrl);
                URLConnection connection = url.openConnection();
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_OK) {
                    Log.d("MyApp", "Registration success");
                } else { …
Run Code Online (Sandbox Code Playgroud)

vpn android android-emulator

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

如何在android上实现HTTP服务器

我在WIFI提供的同一局域网上有两个Android应用程序:

  1. 应用程序(A)在端口8033上打开侦听套接字
  2. 应用程序(B)使用HttpClient访问端口8033上的(A)

如何使(A)可以对(B)进行POST和GET请求?
(A)访问(B)的URL是什么样的?

谢谢大家.

sockets client android httpclient httpserver

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

开发Android中的新"Listen To"操作

我正在完成Android应用程序的开发,以便在时间允许的情况下使用DAAP和UPnP以及其他协议从您的个人音乐集合中流式传输音乐.

我的问题是:如何让我的应用程序响应Android中新的"Listen To"语音命令?

我搜遍了整个地方,无法弄明白.

我认为这是一个广播接收器,但对于我的生活,我找不到哪一个.

任何帮助深表感谢.

android voice-recognition

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

SOAP中的SOAP Web服务和JSON响应

我需要在android中调用基于SOAP的Web服务.我使用以下代码.但它没有调用,因为它以json格式给出响应.那我该怎么办?

有什么帮助吗?

public void callsoapservice() {
    final String METHOD_NAME = "GetLoginString";
    final String SOAP_ACTION = "http://tempuri.org/GetLoginString";
    final String NAMESPACE = " http://tempuri.org/";
    final String URL = "http://209.139.209.216/STMobileWS/MobileWebservice/STOlogin.asmx?WSDL";

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("sCompanyCode", "659");
    request.addProperty("sUserName", "Chad12345");
    request.addProperty("sPassword", "chad");

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER12 );

    envelope.setOutputSoapObject(request);

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);

        // SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;

         System.out.println("Received :" + envelope.bodyIn.toString());

    } catch (Exception e) {
        e.printStackTrace();

        System.out.println("EEEEEEEEE  " + e.toString());
    }
}
Run Code Online (Sandbox Code Playgroud)

android json

6
推荐指数
0
解决办法
887
查看次数

我是否必须在Android中使用加速计才能使照片正确定位?

我注意到当你用原生相机应用拍照时,它们会出现肖像或风景(应该如此),但是,当我使用相机课程在我的应用中拍照时,无论我怎么样,它们总是风景照相.拿着设备.

我真的希望我不必监控设备的方向并手动旋转图像......是否有一种不那么愚蠢的方法来完成这项工作?

TIA

android sensor screen-orientation android-camera

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

如何使用Mono for android和MonoDevelop在linux上设计和构建应用程序?

是否存在任何解释如何在仅Linux工作站上使用mono for android进行开发的信息.

  • Linux上的Mono,好的
  • Linux上的MonoDevelop,好的
  • Linux上的android SDK,好的
  • 在Linux上没有找到 Linux上的Mono (仅找到Windows和Mac)

Mono for android是否限制在Mac和Windows开发工作站上.或者它是否存在能够在Linux上使用它的技巧?

linux android monodevelop xamarin.android

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

为什么某些字符没有调用 onKeyUp 或 onKeyDown?

在我的活动中,我有一个 onKeyUp 和 onKeyDown 事件处理程序,它们为普通字符甚至某些 unicode 字符(如 cedilla (ç))调用。但不适用于 á, à, ü, é, ?, š, ž, è, ...

这是为什么?我怎样才能注册这些按键(或者更好的是,字符)?

我正在带有软键盘(三星和 swype 键盘)的三星 Galaxy S2 上对此进行测试,其中重音字符可通过长按键获得。有趣的是,即使长按相同的 cedilla (ç) 也确实注册了 onKeyUp/Down 事件处理程序。

我在活动中使用 onKeyUp/Down。主视图上没有文本框或任何相关文本。只是一个修改过的 ImageView。

我也在模拟器中对此进行了测试(默认 android 图像 2.3.3)并且行为类似于真实设备。

android event-handling android-emulator android-keypad

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

在ScrollView中拉伸TableLayout

我有这个TableLayout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout" android:layout_height="fill_parent"
android:layout_alignParentBottom="true" android:scrollbars="horizontal|vertical"
android:layout_width="fill_parent" android:scrollbarStyle="outsideInset">
<HorizontalScrollView android:id="@+id/horizontalView" android:layout_height="fill_parent"
            android:layout_width="fill_parent">
    <TableLayout android:id="@+id/reportTableLayout"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:stretchColumns="1">
    </TableLayout>
</HorizontalScrollView>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

我已将所有layout_width设置为fill_parent,但我的Table列似乎没有拉伸并填充宽度空间的其余部分.左边还有一个边距,但我希望我的桌子可以伸展整个屏幕宽度.有任何想法吗?谢谢.

user-interface android scrollview tablelayout

0
推荐指数
1
解决办法
3020
查看次数