小编Big*_*igT的帖子

设置对话框的进度

我有一个异步任务,它不会在完成任务时添加百分比.它始终保持在0%0/100

这是我的代码

     private class getAppInfo extends AsyncTask<String, String, String> {
    /** The system calls this to perform work in a worker thread and
      * delivers it the parameters given to AsyncTask.execute() */
    ProgressDialog dialog;

    @Override
    protected void onPreExecute() {
        if(showLoading == true){
             dialog = new ProgressDialog(SelfHelp.this);
             dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
             dialog.setMessage("Loading");
             dialog.setIndeterminate(true);
             dialog.setCancelable(false);   
             dialog.setMax(100);
             dialog.setProgress(100);
             dialog.show();
        }
    }

    @Override
    protected String doInBackground(String... urls) {                       
        String xml = null;
        int count = 0;
        try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet …
Run Code Online (Sandbox Code Playgroud)

android progressdialog

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

无法解析主机:URL没有与主机名关联的地址

我有一个Web服务调用来关闭一个JSON对象,它只有在我有IP地址而不是主机名时才有效.我使用IP地址很好,但现在我需要拥有主机名.

这是我的代码

    StringBuilder stringBuilder = new StringBuilder();
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
    HttpConnectionParams.setSoTimeout(httpParams, 7000);
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
    HttpPost httpost = new HttpPost(URL);
    try {
        HashMap<String,String>  params = new HashMap<String,String>();
        // Login info
        params.put("username", edtUserName.getText().toString()); 
        params.put("password", edtPass.getText().toString());
        params.put("deviceOS", "Android");
        params.put("deviceOSVersion", android.os.Build.VERSION.RELEASE);
        params.put("language", "0");
        //JSON object holding the login info
        JSONObject holder = new JSONObject(params);

        StringEntity se = new StringEntity(holder.toString());

        httpost.setEntity(se);

        httpost.setHeader("Content-Type", "application/json");
        //Executing the call
        HttpResponse response = httpClient.execute(httpost);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode(); …
Run Code Online (Sandbox Code Playgroud)

android unknown-host androidhttpclient

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

在PHP中推送通知

在尝试执行我的php脚本以向我的iphone发送推送通知后,我收到此错误.

我尝试了一切,没有任何作用.我相信这意味着我ck.pem错了,但我不确定它是key.pem还是cert.pem是错误的.

请帮忙

脚本

    // This this a fake device id:
$deviceToken = '9870h8v088bj29u080af894jj67klfgcv9mmm79k8e4l23456h908743n093e359';

// fake password:
$passphrase = '123456';

// Put your alert message here:
$message = 'New Message';
   ////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client(
                           'ssl://gateway.sandbox.push.apple.com:2195', $err,
                           $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload …
Run Code Online (Sandbox Code Playgroud)

php iphone push-notification apple-push-notifications

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

区域设置:未调用onConfigurationChanged

我希望我的语言动态更改,我正在尝试使用onConfigurationChanged但它没有被调用.我有一个MainActivity,可以创建我的操作栏和viewpager.我的其余页面都是碎片.在我的SettingsFragment中,我有一个按钮可以将语言切换为法语.

langChange.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View vi) {
            MainActivity main = (MainActivity)getActivity();
            main.langChange();
        }

});
Run Code Online (Sandbox Code Playgroud)

然后在我的MainActivity中

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    if (locale != null){
        newConfig.locale = locale;
        Locale.setDefault(locale);
        getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
    }
}

public void langChange(){
    if(currentLanguage == FRENCH_LANGUAGE){
        locale = new Locale("en");
        Locale.setDefault(locale);
        Configuration c = getBaseContext().getResources().getConfiguration();
        c.locale = locale;
        getBaseContext().getResources().updateConfiguration(c,getBaseContext().getResources().getDisplayMetrics());
        currentLanguage = "English";
    }
    else if(currentLanguage == ENGLISH_LANGUAGE){
        locale = new Locale("fr");
        Locale.setDefault(locale);
        Configuration c = getBaseContext().getResources().getConfiguration();
        c.locale = locale;
        getBaseContext().getResources().updateConfiguration(c,getBaseContext().getResources().getDisplayMetrics());
        currentLanguage = "French";
    } …
Run Code Online (Sandbox Code Playgroud)

android locale android-manifest android-fragments

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

PJSip账户注册

我正在尝试将PJSip添加到我正在处理的项目中.我有这种方法来注册我的帐户,但每次都会发生'致命信号11'错误.

这是方法

public int setRegistration() {
    int status = pjsuaConstants.PJ_FALSE;
    /* Register to SIP server by creating SIP account. */
    int[] accId = new int[1];
    accId[0] = 1;

    String uName = getUserName();
    String passwd = getPassword();
    String server = getSIPServer();

    pjsua_acc_config acc_cfg = new pjsua_acc_config();
    pjsua.acc_config_default(acc_cfg);

    acc_cfg.setId(pjsua.pj_str_copy("sip:" + uName + "@" + server));
    acc_cfg.setReg_uri(pjsua.pj_str_copy("sip:" + server));
    acc_cfg.setCred_count(1);

    acc_cfg.getCred_info().setRealm(pjsua.pj_str_copy(server));
    acc_cfg.getCred_info().setScheme(pjsua.pj_str_copy("digest"));
    acc_cfg.getCred_info().setUsername(pjsua.pj_str_copy(uName));
    acc_cfg.getCred_info().setData_type(pjsip_cred_data_type.PJSIP_CRED_DATA_PLAIN_PASSWD.swigValue());
    acc_cfg.getCred_info().setData(pjsua.pj_str_copy(passwd));

    Log.d("status", "acc is adding..");
    status = pjsua.acc_add(acc_cfg, pjsuaConstants.PJ_TRUE, accId);
    Log.d("status", "acc is added");

    if (status == pjsuaConstants.PJ_SUCCESS) { …
Run Code Online (Sandbox Code Playgroud)

android pjsip

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

NSNotification EXC_BAD_ACCESS

这是我得到的错误

Thread 1:EXC_BAD_ACCESS (code=2, address=0xb7ffffc)
Run Code Online (Sandbox Code Playgroud)

在这条线上

[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish
                                                        object:target
                                                      userInfo:[[userInfo copy] autorelease]];
Run Code Online (Sandbox Code Playgroud)

在AsyncImageView.m文件中.

该错误会停止代码,但如果我继续在调试器中冻结Xcode并将其关闭.我该如何解决这个问题?

xcode exc-bad-access nsnotificationcenter

5
推荐指数
2
解决办法
4576
查看次数

如果应用在推送通知上处于活动状态

发送推送通知后,我希望应用程序在我的收件箱页面上打开,以便用户可以在收件箱中看到新消息.我的AppDelegate中有以下代码

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    [self.tabController setSelectedIndex:2]; 
}
Run Code Online (Sandbox Code Playgroud)

当我发送推送消息并且电话处于活动状态时,它会在没有警告的情况下直接进入.我知道它应该用我的代码做什么,但有没有办法改变它

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    if(app.isActive == FALSE)
          [self.tabController setSelectedIndex:2]; 
}
Run Code Online (Sandbox Code Playgroud)

对此有任何见解将有很大帮助.谢谢!

iphone xcode apple-push-notifications

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

ARC自动释放,没有游泳池

我在我的代码中使用ARC,我收到错误

Object 0x781b8e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Run Code Online (Sandbox Code Playgroud)

它打破的线是

  return UIApplicationMain(argc, argv, nil, NSStringFromClass([HomePageAppDelegate class]));
Run Code Online (Sandbox Code Playgroud)

因为我使用ARC,所以不能NSAutoReleasePool像往常那样放置它.我可以使用什么来修复此错误?

iphone xcode automatic-ref-counting

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

枚举时变异数组

我得到的错误是

Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <CALayerArray: 0x7c85080> was mutated while being enumerated.'
Run Code Online (Sandbox Code Playgroud)

我理解的NSGenericException是,我在枚举时从数组中删除了一些东西.仍然知道并环顾四周我似乎无法解决我的问题.这是下面的代码.

-(void)tableView(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     //Checks if message has been read. If message has not it updates the unreadMessages array
     if ([unreadMessage containsObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]] == TRUE && [[[storage_array objectAtIndex:indexPath.row] objectForKey:@"itemtype"] isEqualToString:@"message"]  == TRUE){

     //Unread
     [unreadMessage removeObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
     [unreadMessage writeToFile:[self saveUnreadMessages] atomically:YES];
     //Read
     [readMessage addObject:[NSString stringWithFormat:@"m%@",[[storage_array objectAtIndex:indexPath.row] objectForKey:@"id"]]];
     [readMessage writeToFile:[self saveReadMessages] atomically:YES];
     [tableView reloadData];
 }
 else if …
Run Code Online (Sandbox Code Playgroud)

objective-c nsmutablearray

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

无法实例化服务.GCMIntentService

可能重复:
Android RuntimeException:无法实例化服务

我正在尝试运行此GCMIntentService代码,但我一直在努力Unable to instantiate service.这是我的GCMIntentService代码:

package com.e;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.util.Log;

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService {
  public static String TAG = "GCMIntentService";
  private static String KEY = "c2dmPref";
  private static String REGISTRATION_KEY = "registrationKey";

  public GCMIntentService(String senderId) {
    super(senderId);
    Log.d("GCMIntentService", senderId);
  }

  @Override
  public void onRegistered(Context context, String regId){
    Log.e("registration :","registration :"+regId);

    if (regId != null) {
        Log.d("c2dm", regId);
        Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
        editor.putString(REGISTRATION_KEY, regId);
        editor.commit();
    }
  } …
Run Code Online (Sandbox Code Playgroud)

android google-cloud-messaging

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