我正在尝试包含在应用程序购买中,并且已成功显示可用的 SKU。现在我想进行虚假购买。所以我使用了 appId =“android.test.purchased”。第一次它工作完美,但从接下来它抛出异常,如下所示。
尝试在空对象引用上调用虚拟方法“android.content.IntentSender android.app.PendingIntent.getIntentSender()”
有人遇到过这样的情况吗?
package com.inappbilling.poc;
import java.util.ArrayList;
import org.json.JSONObject;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.android.vending.billing.IInAppBillingService;
public class TestInAppPurchase extends Activity {
private final static String SERVICE_INTENT = "com.android.vending.billing.InAppBillingService.BIND";
private static final String _TAG = "BILLING ACTIVITY";
private final String _testSku = "android.test.purchased";
//available skus
static final String SKU_7DAYS = "7days";
static final String SKU_30DAYS = "30days"; …Run Code Online (Sandbox Code Playgroud) 我是编程新手,我对android有非常基础的知识.我在java中了解到无法实例化接口而这new是Java中用于指示创建实例的关键字.我在Android中遇到了以下代码:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
findViewById(R.id.button1).setOnClickListener(mButton1_OnClickListener);
}
//On click listener for button1
final OnClickListener mButton1_OnClickListener = new OnClickListener() {
public void onClick(final View v) {
//Inform the user the button has been clicked
Toast.makeText(this, "Button1 clicked.", Toast.LENGTH_SHORT).show();
}
};
}
Run Code Online (Sandbox Code Playgroud)
上面的代码OnClickListener是一个公共接口,onClick(final View v)是一个抽象的方法,这就是我的问题:OnClickListener作为一个接口,如何使用new上面的例子中的关键字创建它的实例?
我是Android安全概念的新手。
我一直在阅读一些博客,以了解我们可以使用公钥加密数据并可以使用各自的私钥解密数据。加密似乎没有任何问题,但是当我尝试对其进行解密时,它会抛出:
javax.crypto.BadPaddingException:错误:0407106B:rsa例程:RSA_padding_check_PKCS1_type_2:块类型不是02。
我的代码如下:
public String RSAEncrypt(final String plain, PublicKey publicKey ) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte [] encryptedBytes = cipher.doFinal(plain.getBytes());
String encrypted = bytesToString(encryptedBytes);
System.out.println("EEncrypted?????" + encrypted );
return encrypted;
}
public String RSADecrypt(String encryptedBytes,PrivateKey privateKey ) throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException {
Cipher cipher1 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher1.init(Cipher.DECRYPT_MODE, privateKey);
byte [] decryptedBytes = cipher1.doFinal(stringToBytes(encryptedBytes));
String decrypted = new String(decryptedBytes);
System.out.println("DDecrypted?????" + decrypted);
return decrypted;
}
public String bytesToString(byte[] …Run Code Online (Sandbox Code Playgroud) 让我从以下示例开始:
public void loadList(ArrayList<Calls> list) {
List<Calls> calls = new ArrayList<Calls>();
calls.addAll(list);
}
Run Code Online (Sandbox Code Playgroud)
哪里Calls是一个简单的类:
public class Calls {
public long ms;
public name;
}
Run Code Online (Sandbox Code Playgroud)
我想List<Calls>根据ms字段按升序或降序对上面的内容进行排序.我遇到了一些例子,Comparator但仍然不清楚.
我有两个数组
1) String[] images = {"#1","#2", "#3", "#4", "#5" };
2) String[] items = {"1","2", "3", "4", "5", "6", "7", "8" };
项目可能会有所不同,但图像阵列是固定的.我喜欢输出映射
image 1 => item 1
image 2 => item 2
image 3 => item 3
image 4 => item 4
image 5 => item 5
image 1 => item 6
image 2 => item 7
image 3 => item 8
Run Code Online (Sandbox Code Playgroud)
等等.我的工作如下,
public static void main(String[] args) {
for( int y=0;y< items.length;y++ ){
for( int i=0;i< images.length;i++ ){ …Run Code Online (Sandbox Code Playgroud) 当我编写android时,我遇到了以下事情
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = _inflater.inflate(R.layout.abstract_list_row_item, null);
move.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// if btn is clcked then data is changed an we need to refresh framents
MainAppDataController.getInstance().setIsDataChanged(true);
callWhiteListDB = new CallWhiteListDB(_context);
callWhiteListDB.openToWrite();
callWhiteListDB.insert(allContacts.get(position).name, allContacts.get(position).number);
callWhiteListDB.close();
callBlackListDB = new CallBlackListDB(_context);
callBlackListDB.openToWrite();
callBlackListDB.deleteSingleItem(allContacts.get(position).dbId);
callBlackListDB.close();
populateList(position);
notifyListView(view);
}
});
return convertView;
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,getView()方法有像int position,View convertView,ViewGroup parent这样的参数.我的观察是在我开始使用位置变量时onclick(),Eclipse抛出编译错误并要求将位置作为final.我为什么要把它作为最终版?AFAIK final用于常量.