小编The*_*der的帖子

如何检查文件是否存在,如果没有在异步任务中的sdcard中创建新文件

我想从服务器下载pdf并存储在SD卡上.我尝试类似下面的代码,但它不会进入其他条件,因为我没有创建一个文件仍然会给MSG作为文件存在.为什么会这样?

String pdf;
String filenameWithExtension="";

protected void onCreate(Bundle savedInstanceState) {

        Intent intent=getIntent();
        pdf=intent.getStringExtra("pdfurl");
        String PATH2 = Environment.getExternalStorageDirectory()+"/pictures";
        Log.v("log_tag initial path", "PATH: " + PATH2);
        File file2 = new File(PATH2);
        if(file2.exists()==true)
        {
        }else
        {   
            Log.v("directory is created", "new  dir");
            file2.mkdir();
        }

        /**extracting the pdf filname from url**/
        int slashIndex = pdf.lastIndexOf('/');
        int dotIndex = pdf.lastIndexOf('.');
        filenameWithExtension=pdf.substring(slashIndex + 1);

        DownloadFile downloadFile = new DownloadFile(filenameWithExtension);
        downloadFile.execute(pdf);
}
private class DownloadFile extends AsyncTask<String, Integer, String>{

        String filename="";
        public DownloadFile(String _filename) {
            this.filename=_filename;

        }
        String …
Run Code Online (Sandbox Code Playgroud)

android

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

Youtube嵌入了在webview中无效的视频.这段代码出了什么问题?

我是android的新手.我现在面临两个问题 1.我解析了xml文件并在webview中显示它,其中包含视频和文本.当我点击视频时,它将无法播放.在xml视频中有youtube嵌入.

为什么会这样?

1.第一个问题:代码和图像

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.web_view);
    Intent intent=getIntent();
    String urlsting=intent.getStringExtra("str"); 
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginState(PluginState.ON);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.setInitialScale(100);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.loadDataWithBaseURL(null, urlsting,"text/html", "utf-8", null);
}
Run Code Online (Sandbox Code Playgroud)

当我浏览视频时,它开始浏览并只显示黑屏,然后什么都不会发生.

![] [1]

2. 我有你管的嵌入式视频网址,我用html标签给出并尝试加载它.它们也不适合我.我检查了一些问题和博客,也没有设置,然后也无法显示视频.将不胜感激.谢谢.

String video= "<table bgcolor=\"#666666\"><tr><td><iframe width=\"300\" height=\"260\"     frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe width=\"300\" height=\"260\" frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/lBMMTeuJ_UQ?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe width=\"300\" height=\"260\" frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/BZMkY3y7nM0?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td></table>"; 

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginState(PluginState.ON);
    mWebView.getSettings().setPluginsEnabled(true);
    //mWebView.loadDataWithBaseURL(null,load,"text/html","UTF-8",null);
    mWebView.loadData(video,"text/html","UTF-8");
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我将youtube embeded视频加载到webview,但它们也无法正常工作.

![] [2]

我正在使用android 2.3.3version.我也想要澄清,有任何要求在模拟器上安装adobe flash player,但我认为不,因为视频在浏览器中工作.任何人都可以告诉我是对还是错?请尽量给我解决方案因为我很久以前就遇到了这个问题..

我也尝试使用object标签如下:

        String obj="<object width=\"300\" height=\"260\"><param name=\"movie\" value=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\"?version=3&amp;hl=pt_BR&amp;rel=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param …
Run Code Online (Sandbox Code Playgroud)

embed youtube video android android-webview

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

如何以编程方式打开设备基座设置?

我必须通过代码打开设备停靠设置.我搜索但没有得到适当的解决方案.在三星Galaxy s-3中,它通过设置 - >附件.我尝试了以下代码,但没有奏效

startActivityForResult(new Intent(Settings.System.getString(getContentResolver(), DOCK_SETTING)), 0);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 在此输入图像描述

settings android dock

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

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

UIAlertController无法在iOS 9中运行

我添加了显示登录和密码文本字段的UIAlertController代码,它适用于iOS 8但在iOS 9中不起作用.文本字段缩小,如下图所示 在此输入图像描述

我正在尝试的代码如下:

 - (void)toggleLoginLdap:(UIViewController *)currentVC
 {

 if ([UIAlertController class])
        {


            self.alertController= [UIAlertController
                                       alertControllerWithTitle:@"Title of Msg"
                                       message:@"Hello"
                                       preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction * action){
                                                           NSString *userName = self.alertController.textFields[0].text;
                                                           NSString *password = self.alertController.textFields[1].text;



                                                       }];
            UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
                                                           handler:^(UIAlertAction * action) {


                                                               [self.alertController dismissViewControllerAnimated:YES completion:nil];

                                                           }];


            [self.alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                 textField.placeholder = @"Username/Email";
                 //textField.preservesSuperviewLayoutMargins = YES;
                textField.autoresizesSubviews = YES;
            }];
            [self.alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
                textField.placeholder = @"Password";
                textField.secureTextEntry = YES;
            }];
            //alertController.view.autoresizesSubviews = YES;
            [self.alertController …
Run Code Online (Sandbox Code Playgroud)

objective-c uialertview uialertcontroller ios9 xcode7

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