小编Moe*_*eez的帖子

保护php api在android应用程序中使用

我是android开发的新手.我正在android studio用于开发应用程序.我做过的事情

  1. 在其中创建了一个DB包含两个表的表MySQL.
  2. api's为两者GETPOST方法创建了两个单独的.
  3. 成功访问了两者 api's

我现在取得的成就

  1. 能够GET获得GET数据api.
  2. 能够POST使用POST 进行数据处理api

我现在要做什么

我希望我的api在线发布,即我想将我的服务部署到服务器并访问它们.此时,我能够在服务器上部署服务并访问它们.

现在我希望我的服务(api's)得到保护.为此我搜索了很多文章并找到了两种方法.

  1. 使用yii框架.有人告诉我使用它,因为它自动保护了api's.但我不确定它是否成功.
  2. 手动保护 api's

至于点1,框架将是有用的,但它对我来说是新的,它需要时间与它合作,因为我已经创建了Web服务.

为了点2我得到了一些信息

  1. 使用HMAC_SHA1
  2. 使用PHP检测移动设备

两个链接似乎都很好,但链接1并没有给我很多信息.

显然我想要保护我的两个 api's

现在是代码部分

GET_DATA.php

require_once ('config.php');

$sql = "SELECT * FROM users";


$r = mysqli_query($con,$sql);

$result = array();

while($row = mysqli_fetch_array($r)){
array_push($result,array(
    'Id'=>$row['Id'],
    'Name'=>$row['Name']
));}
Run Code Online (Sandbox Code Playgroud)

echo json_encode(array('users'=> $ result)); …

php mysql api android yii

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

在谷歌地图android中移动带有gps的标记

我想使标记的举动中GOOGLE MAP,而gps位置变化只是喜欢UBER的应用程序.我找到了一些解决方案但无法解决我的问题.解决方案是12

以下是我的onLocationChange()方法

public void onLocationChanged(Location location) {

    double lattitude = location.getLatitude();
    double longitude = location.getLongitude();

    mLastLocation = location;
    if (mCurrLocationMarker != null) {
        mCurrLocationMarker.remove();
    }
    //Place current location marker
    LatLng latLng = new LatLng(lattitude, longitude);
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("I am here");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));

    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);

    tv_loc.append("Lattitude: " + lattitude + "  Longitude: " + longitude);

    //move map camera
    mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

    //stop location updates
    if (mGoogleApiClient …
Run Code Online (Sandbox Code Playgroud)

gps android google-maps google-maps-api-3

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

Canvas js export启用不能在android设备上运行

我正在研究CANVASjS并构建一个在图表上显示数据的示例应用程序.我已经启用export保存在图表.png.jpeg和打印也.虽然ripple emulator在导出上部署它是完美的,但是当我部署它时android device它不起作用.下面是我启用导出的代码部分.

var chart = new CanvasJS.Chart("container", {
            zoomEnabled: true,
            zoomType: "xy",
            animationEnabled: true,
            animationDuration: 2000,
            exportEnabled: true,
// all other chart code 
});
Run Code Online (Sandbox Code Playgroud)

更新1:

 function drawChart(data)
            {
                var chart = new CanvasJS.Chart("container", {
                    zoomEnabled: true,
                    zoomType: "xy",
                    animationEnabled: true,
                    animationDuration: 2000,
                    exportEnabled: true,
                    exportFileName: "Column Chart",
                    title: {
                        text: "Energy vs Date Time"
                    },
                    axisY: {
                        title: "EnergykWh",
                        interlacedColor: "#F8F1E4",
                        tickLength: 10,
                        suffix: "k",
                    },
                    legend: …
Run Code Online (Sandbox Code Playgroud)

javascript android canvasjs

13
推荐指数
1
解决办法
708
查看次数

使用TabLayout在ViewPager中的Google地图片段中夸大异常

我制作了一个应用程序,其中我在我的位置显示了带有GPS位置标记的Google地图.此地图位于第一个选项卡上,我还有另外两个选项卡,如下图所示

在此输入图像描述

现在我面临一个问题,即当我从选项卡1移动到选项卡2然后再转到选项卡1时它完美地工作,但是当我移动到选项卡3然后移回选项卡1或选项卡2时,应用程序崩溃并给出以下内容例外情况LogCat:

01-27 18:35:26.190 9414-9414/com.example.accurat.faisal E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.accurat.faisal, PID: 9414
  android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class fragment
      at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
      at com.example.accurat.faisal.MyLocation.onCreateView(MyLocation.java:62)
      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2184)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1298)
      at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
      at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
      at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1969)
      at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:620)
      at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
      at android.support.v4.view.ViewPager.populate(ViewPager.java:1268)
      at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
      at android.support.v4.view.ViewPager$3.run(ViewPager.java:273)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
      at android.view.Choreographer.doCallbacks(Choreographer.java:686)
      at android.view.Choreographer.doFrame(Choreographer.java:619)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:7325)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
      at …
Run Code Online (Sandbox Code Playgroud)

android google-maps inflate-exception google-maps-android-api-2 android-tablayout

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

无法在android中选择微调项

我添加了一个微调器并将 a 列表加载到其中。使用app我想从列表中选择。但我做不到。

 subDivisionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
    {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
        {

            if (isUserAction) {
                if (position != selectedSubDivisionPosition) {
                    resetForm(false, false);
                }
            }
            selectedSubDivision = subDivisionList.get(position);
            selectedSubDivisionPosition = position;
            isUserAction = true;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
Run Code Online (Sandbox Code Playgroud)

当我点击微调器时,列表会显示,但当我点击一个项目时,它会回到原始状态。即选定的项目在点击后不显示。见下图

在此处输入图片说明

更新 1

下面是我的resetForm方法

private void resetForm(boolean all, boolean signal) {

    this.refNofield1.setText("");
    this.consumerNameEditText.setText("");
    this.consumerAddressEditText.setText("");
    this.longitudeEditText.setText("");
    this.latitudeEditText.setText("");
    this.placeEditText.setText("");
    this.tarifEditText.setText("");
    this.sLoadEditText.setText("");
    this.cableLengthEditText.setText("");
    this.runningLoadEntryA.setText("");
    this.runningLoadEntryB.setText("");
    this.runningLoadEntryC.setText("");
    this.ctRatio.setText("");
    this.transformerRating.setText("");
    this.newSurveyImagesBitmap = new …
Run Code Online (Sandbox Code Playgroud)

android spinner android-studio android-studio-4.0

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

以原始形式保存图像且不压缩

我想保存图像而不压缩它,并希望以原始形式保存它,即当图像被压缩时,图像尺寸会减小并且图像变小。我为此目的使用本机相机。我正在工作android studio。我正在制作一个应用程序,在其中使用相机来保存图像。但图像经过压缩,非常小,质量也很低。

下面是我保存图像的代码

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
    if(requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
    {
        if(resultCode == Activity.RESULT_OK)
        {
            Bitmap bmp = (Bitmap)data.getExtras().get("data");
            ByteArrayOutputStream stream = new ByteArrayOutputStream();

            bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            byte[] byteArray = stream.toByteArray();

            // convert byte array to Bitmap
            Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

            if(isStoragePermissionGranted())
            {
                SaveImage(bitmap);
            }


        }
    }else {
        switch (requestCode) {
            case 1000:
                switch (resultCode) {
                    case Activity.RESULT_OK:
                        // All required changes were successfully made …
Run Code Online (Sandbox Code Playgroud)

android image android-camera android-bitmap

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

EF 在表中插入值一段时间后失败

我正在工作EF。我试图插入一个表,插入函数在一个线程中。

private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
    int bytes = port.BytesToRead;
    //string indata = sp.ReadExisting();

    Thread.Sleep(50);

    try
    {
        receivedBytes = port.BaseStream.Read(buffer, 0, (int)buffer.Length);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message.ToString());
    }

    var receiveData = BitConverter.ToString(buffer, 0, receivedBytes);
    var finalData = receiveData.Replace("-", "");
    //Thread.Sleep(100);

    Console.WriteLine("Thread Going to Start");

    new Thread(() => {
            SaveData(finalData);
        }).Start(); // starting the thread

    port.DiscardOutBuffer(); 
    port.DiscardInBuffer();
}
Run Code Online (Sandbox Code Playgroud)

这是我的保存数据功能

public void SaveData(string finalData)
{
    Console.WriteLine(LineNumber() + "Data Transmiting...");
    thread = Thread.CurrentThread;         


mdc_dbEntities e = new mdc_dbEntities(); …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework savechanges entity-framework-6

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

如何正确连接 MySQL 数据库和 C# 应用程序?

我正在尝试连接我的MySQL数据库,C#但它没有连接。

我在用

static string connstring = @"server=my.live.ip;userid=user;password=123;database=db_name;port=3306";
Run Code Online (Sandbox Code Playgroud)

但我仍然得到

使用方法 'mysql_native_password' 对用户 'user' 的主机 'my.live.ip' 进行身份验证失败并显示消息:用户 'user'@'202.xxx.xxx.xxx' 访问被拒绝(使用密码:否)`

我已经对其进行了搜索,但没有找到任何合适的解决方案。

PS:live IP我使用的是azure。即MySQL数据库通过托管在 azure 服务器上xampp

任何帮助将不胜感激

c# mysql ado.net azure

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

Visual Studio无法在我的rest api客户端中添加swagger元数据文件

我是移动开发的新手.因为我熟悉c#.net所以我正在使用xamarin插件visual studio.我已经创建了一个示例app,我已经使用过SQLite,创建了一个DB然后执行了CRUD操作.在这一点上,一切都很好.但我已经有了local DB,我想用它.为此我已经做了一个offline Azure api使用swaggerRelease我已经保存文件locally使用File Systemin release选项VS.现在我想添加我的应用程序,rest api client并希望使用我的本地数据库.但是,当我尝试添加作为休息api客户端然后我选择select an existing swagger file所以在浏览时我找不到任何文件.供参考,请参阅下面的图片

在此输入图像描述

因此,当我点击浏览并转到我保存文件swagger的位置时,我没有得到任何信息,如下图所示

在此输入图像描述

它还找到了.json我的发布api中不存在的扩展文件.

我不知道为什么会发生这种情况,同样如上所述,我是移动开发的新手,我不知道该怎么做.请看我的轰鸣声形象swagger UI

在此输入图像描述

任何帮助将受到高度赞赏

rest xamarin.android swagger visual-studio-2015 azure-api-apps

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

在 android studio 中以编程方式删除按钮单击上的布局

我在单击按钮时添加布​​局。

 private void addLayout() {
    layout2 = LayoutInflater.from(mContext).inflate(R.layout.product_layout, mLinearLayout, false);
    productAuto = (AutoCompleteTextView) layout2.findViewById(R.id.tv_product);
    qtyEditText = (EditText) layout2.findViewById(R.id.prod_qty);
    prodPriceEditText = (EditText)layout2.findViewById(R.id.prod_price);
    prodSpecsEditText = (EditText)layout2.findViewById(R.id.prod_specs);
    removeProduct = (Button)layout2.findViewById(R.id.btn_rmv);
    mLinearLayout.addView(layout2);
    setProd();
    this.initListenersPrd(getActivity());
}
private void initListenersPrd(final Context context) {
    productAuto.setOnItemClickListener((parent, view, position, id) -> {
        String newName = parent.getItemAtPosition(position).toString();
        ProductDetail productDetail = mProductManager.getProductByPrdName(newName);
        if (productDetail != null) {
           this.prodPriceEditText.setText(productDetail.getPrice());
           this.prodSpecsEditText.setText(productDetail.getProductSpec());
        }
    });

    removeProduct.setOnClickListener(v -> {
       if (mLinearLayout.getChildCount()>0)
       {
           ((LinearLayout)mLinearLayout.getParent()).removeView(mLinearLayout);
       }

    });}
Run Code Online (Sandbox Code Playgroud)

现在我想从应用程序中删除特定的产品表单,因此我已((LinearLayout)mLinearLayout.getParent()).removeView(mLinearLayout);单击“删除”按钮。但它删除了动态添加的整个布局。

图形用户界面

在此输入图像描述

正如您在上图中看到的,我添加了 4-5 个产品布局,但是当我单击“删除”按钮时,我删除了所有布局。

更新1

我在主布局中添加了以下布局,然后以编程方式调用其中的产品布局

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)

android android-linearlayout android-view

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