小编Kev*_*vek的帖子

与Android应用程序中的客户端证书的HTTPS连接

我正在尝试用我正在编写的Android应用程序中的HTTPS连接替换当前正在运行的HTTP连接.HTTPS连接的额外安全性是必要的,因此我不能忽略此步骤.

我有以下内容:

  1. 服务器配置为建立HTTPS连接,并需要客户端证书
    • 此服务器具有由标准大型CA颁发的证书.简而言之,如果我通过Android中的浏览器访问此连接,它可以正常工作,因为设备信任库可以识别CA. (所以它不是自签名的)
  2. 客户端证书,基本上是自签名的.(由内部CA发布)
  3. 一个Android应用程序,它加载此客户端证书并尝试连接到上述服务器,但具有以下问题/属性:
    • 当服务器被配置为客户端可以连接到服务器要求客户端证书.基本上,如果我使用SSLSocketFactory.getSocketFactory()连接工作正常,但客户端证书是此应用程序规范的必需部分,因此:
    • javax.net.ssl.SSLPeerUnverifiedException: No peer certificate当我尝试连接我的自定义时SSLSocketFactory,客户端会产生异常,但我不完全确定原因.在互联网上搜索各种解决方案后,这个例外似乎有点模棱两可.

以下是客户端的相关代码:

SSLSocketFactory socketFactory = null;

public void onCreate(Bundle savedInstanceState) {
    loadCertificateData();
}

private void loadCertificateData() {
    try {
        File[] pfxFiles = Environment.getExternalStorageDirectory().listFiles(new FileFilter() {
            public boolean accept(File file) {
                if (file.getName().toLowerCase().endsWith("pfx")) {
                    return true;
                }
                return false;
            }
        });

        InputStream certificateStream = null;
        if (pfxFiles.length==1) {
            certificateStream = new FileInputStream(pfxFiles[0]);
        }

        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        char[] password = "somePassword".toCharArray();
        keyStore.load(certificateStream, password); …
Run Code Online (Sandbox Code Playgroud)

java ssl https android certificate

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

使用冻结列和冻结标题创建表/网格

我正在开发一款小型Android应用.我需要这个Android应用程序的一部分是有一个水平和垂直滚动的网格.但是,最左边的列需要冻结(始终在屏幕上,而不是水平滚动的一部分).同样,顶部标题行需要冻结(不是垂直滚动的一部分)

如果以上内容没有太大意义,这张图片将有希望清楚地描述:

我想做什么的例子

关键:

  1. 白色:根本不滚动
  2. 蓝色:垂直滚动
  3. 红色:水平滚动
  4. 紫色:垂直和水平滚动

要做到这些尺寸中的一个很容易,我已经这样做了.但是,我无法让这两个维度发挥作用.(也就是说,我可以将底部部​​分全部变为蓝色,或者我可以将正确的部分全部变为红色,但不完全如上所述)我的代码如下所示,基本上会产生以下内容:

是)我有的!

result_grid.xml:

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/lightGrey">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@id/summaryTableLayout"
        android:layout_weight="0.1"
        android:layout_marginBottom="50dip"
        android:minHeight="100dip">
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical">
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TableLayout
                    android:id="@+id/frozenTable"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_marginTop="2dip"
                    android:layout_marginLeft="1dip"
                    android:stretchColumns="1"
                    />

                <HorizontalScrollView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@id/frozenTable"
                    android:layout_marginTop="2dip"
                    android:layout_marginLeft="4dip"
                    android:layout_marginRight="1dip">

                    <TableLayout
                        android:id="@+id/contentTable"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:stretchColumns="1"/>
                </HorizontalScrollView>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="vertical"
        android:layout_weight="0.1"
        android:layout_alignParentBottom="true">
        <Button
            android:id="@+id/backButton"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="Return"/>
    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

Java代码:

private boolean showSummaries;

private TableLayout summaryTable;
private TableLayout frozenTable;
private …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-gridview

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

Application子类中的startActivity

我有一个小的Android应用程序,我在其中直接指定我的应用程序并在ApplicationSubclass'onCreate中进行一些应用程序范围的设置,但是我收到以下错误(注意,我知道FLAG_ACTIVITY_NEW_TASK):

Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
    at android.app.ContextImpl.startActivity(ContextImpl.java:644)
    at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
    at somePart.ofA.nameSpace.ApplicationSubclass.sendNotificationEmail(ApplicationSubclass.java:186)
Run Code Online (Sandbox Code Playgroud)

当我抛出一些异常时,我正在调用这个sendNotificationEmail,我抓住它们,以便应用程序的用户可以发送一个包含异常信息的小电子邮件,以便我可以更轻松地修复可能出现的任何内容或引导它们解决他们的问题.

以下是一些相关代码:

manifest.xml文件:

<application android:label="@string/app_name" android:icon="@drawable/icon" android:name=".ApplicationSubclass">
// ... some stuff, including all of my app's activities
</application>
Run Code Online (Sandbox Code Playgroud)

ApplicationSubclass定义为:

public class ApplicationSubclass extends Application {
   // Multiple methods, including an override of onCreate

  public void sendNotificationEmail(String emailBody) {
      Intent emailIntent = new Intent(Intent.ACTION_SEND);
      emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      emailIntent.setType("text/html");
      emailIntent.putExtra(Intent.EXTRA_EMAIL, notificationRecipients);
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "MyAppName Error");
      emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody); …
Run Code Online (Sandbox Code Playgroud)

android android-activity

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

我怎样才能重构这两种方法

嗨我有两种方法,还有三种方法(在这个问题中没有提到)..

我怎么能重构这些..

方法1:

   public  DataTable GetVisits(System.DateTime startdate , System.DateTime enddate)
     { 


         const string sql  = @"SELECT CONCAT(UPPER(SUBSTRING(visit_Status, 1, 1)), SUBSTRING(visit_Status FROM 2))  as Status, COUNT('x') AS Visits
                              FROM visits
                              WHERE visit_Date BETWEEN @startdate AND @enddate
                              GROUP BY visit_Status";

         var tblvisits = new DataTable();

         using (var conn = new MySql.Data.MySqlClient.MySqlConnection(connectionstring))
         {
             conn.Open();

             var cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, conn);


             var ds = new DataSet();

             var parameter = new MySql.Data.MySqlClient.MySqlParameter("@startdate", MySql.Data.MySqlClient.MySqlDbType.DateTime);
             parameter.Direction = ParameterDirection.Input;
             parameter.Value = startdate.ToString(dateformat);
             cmd.Parameters.Add(parameter);

             var parameter2 = new …
Run Code Online (Sandbox Code Playgroud)

.net c# refactoring winforms

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

为什么还需要错误返回类型?

我想在之前的函数中绘制一条线.因此,我需要一个返回函数,因此在图形函数中绘制线条更加顺畅.

我很困惑,为什么还有错误,因为我放了返回功能.请帮我..

"Program.java:45:无效的方法声明;需要返回类型"

   public static SLL(int SLL)

   public Program()
  {
     super("MyProgram"); //window name
     .....
     computeButton.addActionListener(this);
  }


   public void actionPerformed(ActionEvent ee)
  {
  }
   public static SLL(int SLL)
  {  ....

     HomePosition HP[][] = new HomePosition[2][6];
     HomePosition DP[][]= new HomePosition[2][6];
     HomePosition FB[][] =new HomePosition[2][6];
     ...
     FB[1][0].x= FB[2][0].x=40;
     FB[1][0].y=FB[2][0].y=40;

     HP[1][0].x = 40;       HP[1][0].y = 30;        
     HP[1][1].x = 26;       HP[1][1].y = 30;       


     DP[1][0].x = 30;           DP[1][0].y =40;    
     DP[1][1].x = 16;           DP[1][1].y = 40;   

     SLL.SLx[m][n]=HP[m][n].x;

     return SLL;
  }

   public void paint(Graphics g) {
     super.paint(g);      
     }


      BasicStroke …
Run Code Online (Sandbox Code Playgroud)

java

-1
推荐指数
1
解决办法
588
查看次数