小编pt1*_*123的帖子

C++ 多态性和向量,将向量的派生类指向向量的基类

说:Apple 是从 FruitPicker 基类派生的,那么 ApplePicker 类是从 FruitPicker 基类派生的。
ApplePicker 类有一个vector<Apple> appleList,Fruit picker 类有一个指向vector<Fruit>ie的指针vector<fruit>* fruitList

我需要能够将向量设置为该指针,以便可以在水果选择器类中运行抽象方法(因为它们只涉及水果成员)。但当我尝试这样做时,我在设置时遇到了麻烦:

this->fruitList = &(this->AppleList);
Run Code Online (Sandbox Code Playgroud)

它给了我错误cannot convert to vector<Apple> to vector<Fruit>。我尝试了静态转换,它给了我同样的错误。我对非向量基类和派生类做了类似的事情,效果很好。

我是 C++ 新手,我通过 NDK 在 Android 上使用它。

我试图做的事情也是不可能的,我必须使用像 这样的指针向量vector<Fruit*>

c++ polymorphism pointers vector

4
推荐指数
1
解决办法
1112
查看次数

Okhttp在不下载文件的情况下检查文件大小

okhttp 的常见示例涵盖了 get 和 post 的场景。

但我需要通过 url 获取文件的文件大小。由于我需要通知用户,并且只有在获得他们的批准后才能下载文件。

目前我正在使用此代码

URL url = new URL("http://server.com/file.mp3");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
int file_size = urlConnection.getContentLength();
Run Code Online (Sandbox Code Playgroud)

在这个 stackoverflow 问题中提到如何在下载文件之前知道文件的大小?

哪个有效,但是当我在我的项目中使用 okhttp 来处理其他 get 请求时,我也希望将它用于这种情况。

android http-content-length okhttp

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

如何增加Android ActionBar按钮的文字大小?

我有两个ActionBar按钮:一个只显示一个图标,另一个没有图标 - 我使用文本显示应用程序接收的新项目数.问题是文字尺寸太小,想要做得更大.

尝试造型:

<item name="android:actionBarStyle">@style/MyActionBar</item>
Run Code Online (Sandbox Code Playgroud)

没有效果.

试图加载自定义视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:gravity="fill_vertical"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:minWidth="64dip"
    android:src="@drawable/ic_action_refresh" />

<ImageButton
    android:id="@+id/button1"
    android:scaleType="centerInside"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    style="?android:attr/actionButtonStyle"
    android:text="0" />
Run Code Online (Sandbox Code Playgroud)

也没有成功.

但是,我宁愿维护普通ActionBar按钮的样式和属性,只需增加文本大小.有没有办法实现这一目标?我不使用Sherlock,下面是我的ActionBar代码.

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
<item 
    android:id="@+id/action_about" 
    android:title="@string/action_about" 
    android:showAsAction="never">        
</item>
<item 
    android:id="@+id/action_counter"  
    android:title="@string/action_counter"
    android:showAsAction="always|withText">
</item>
<item 
    android:id="@+id/action_refresh"  
    android:title="@string/action_refresh"
    android:icon="@drawable/ic_action_refresh" 
    android:showAsAction="always">        
</item>
Run Code Online (Sandbox Code Playgroud)

我想仅更改action_counter的文本大小.

android text-size actionbarsherlock android-actionbar

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

防止/使二进制组件修补变得困难

我不确定术语是否正确您可以使用哪些代码实践来使某人难以修改二进制/程序集以绕过检查:

例如在源代码中.

bool verificationResult = verify();
if (verificationResult){
 allow_Something();
}else{
 prevent_Something();
} 
Run Code Online (Sandbox Code Playgroud)

如果查看上述代码的反汇编版本的人可以修改'jump opcodes(?)'以运行allow_Something,即使验证结果为false也是如此.

这里有类似的内容 http://www.codeproject.com/Articles/18961/Tamper-Aware-and-Self-Healing-Code#pre0

注意我在C++中创建二进制文件,以便在Android上通过NDK使用它.

android patch disassembly android-ndk

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

Lollipop 5.0示例许可检查应用程序在仿真器(AVD)上崩溃

当运行Google在sdk/extras/google/play_licensing中提供的示例许可证检查应用程序时,它会在运行Lollipop(5.0)的模拟器(AVD)上崩溃(我没有运行5.0的手机).它在运行Kitkat的手机上运行良好.

在4.4 Kitkat上,它给出了一个警告

Implicit intents with startService are not safe: Intent { act=com.android.vending.licensing.ILicensingService } 

android.content.ContextWrapper.bindService:538 com.google.android.vending.licensing.LicenseChecker.checkAccess:150 LicActivity.doCheck:126 
Run Code Online (Sandbox Code Playgroud)

我不确定5.0他们是否已将其从警告移至完全爆炸错误.

我不知道如何将隐式intent调用转换为显式调用.它在LicenceChecker类中被调用

   boolean bindResult = mContext
                            .bindService(
                                    new Intent(
                                            new String(
                                               Base64.decode("HEX_TEXT"))),
                                    this, // ServiceConnection.
                                    Context.BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)

BASE 64解码为com.android.vending.licensing.ILicensingService

我刚收到错误消息不幸的是,许可证检查程序已停止.在对话框中.

它在logcat中显示此消息

java.lang.RuntimeException: Unable to instantiate application com.android.vending.VendingApplication: java.lang.ClassNotFoundException:

 Didn't find class "com.android.vending.VendingApplication" on path: DexPathList[[zip file "/system/app/LicenseChecker/LicenseChecker.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
Run Code Online (Sandbox Code Playgroud)

有人报道了一段时间但仍然没有解决方案

http://code.google.com/p/android/issues/detail?id=61680

android android-intent android-lvl android-5.0-lollipop

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