0%

反编译APK文件需要dex2jar和jd-gui这两个工具,我已经打包了,可以本文底部下载。 第一步、下载我提供的工具后解压。 第二步、把目标APK文件扩展名改为zip,用WINRAR或者其他压缩软件打开,解压其中的classes.dex,并放到上面第一步解压出来的工具目录里 如图: 第三步、双击执行目录中的First.bat,会在当前目录生成一个classes.dex.dex2jar.jar文件 第四步、打开jd-gui.exe,File-Open File找到刚才生成的classes.dex.dex2jar.jar文件 OK,现在你可以看到Java源代码了. 如果需要查看APK中的XML文件以及图片,可以用apktool,这里也一并附上,已经放进压缩包里了,上面的截图没有,使用方法: apktool.bat d apk名 解压目录 工具下载: [download id=”23”]

C# Hashtable用法,C#有些东西使用方法还是跟Java不同,记一下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable table = new Hashtable();
            table.Add("a", "aaa");
            table.Add("c", "ccc");
            table.Add("b", "bbb");
            //添加元素 key,value

            IDictionaryEnumerator ide=table.GetEnumerator();
            while (ide.MoveNext()) {
                DictionaryEntry entry = ide.Entry;
                Console.WriteLine(entry.Key + "=" + entry.Value);
            }
            //循环输出所有键和值,不一定是按上面添加的顺序
            Console.WriteLine(table["b"]);
            //输出指定键的值 
            
            

        }
    }
}

1、构造方法:结构体必须对所有对象初始化,但类不是必须的 2、在定义构造方法后,类不会自动生成默认不带参的构造方法,但结构体会 3、结构体中不允许定义不带参数的默认构造方法 4、实例化对象/值:结构体可以不传任何参数(即使定义的构造方法是有参数的),但类必须与构造方法对应(因为第2条)。 5、这是最重要的区别:类是引用类型,而结构体是值类型 6、在类中声明对象的同时可以初始化该对象,但结构体中不能

除下面的方法外,还可以添加HyperlinkButton,设置NavigateUri属性来实现跳转。 WP7界面间的跳转相对于Android比较怪,跟HTML倒比较相似,就是生成一个Uri,这个Uri可以跟HTML中的URL一样带参数,然后跳转到这个URL就行。 效果: 只为演示页面的跳转,所以很简单,就一个按钮。 有两个Page,一个是建立项目时自动生成的MainPage,另一个是后来添加的Page1。WP7也采用XAML定义布局,文件扩展名为xaml,其实就本质上就是xml。 虽然布局很简单,但是因为是新手,还是贴一下: MainPage.xaml:

<phone:PhoneApplicationPage 
    x:Class="PhoneApp2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="MainPage" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Jump to page1" Height="73" HorizontalAlignment="Left" Margin="69,83,0,0" Name="button1" VerticalAlignment="Top" Width="277" Click="button1_Click" />
        </Grid>
    </Grid>
 </phone:PhoneApplicationPage>

就一个按钮,定义了Click事件调用button1_Click方法 Page1.xaml:

<phone:PhoneApplicationPage 
    x:Class="PhoneApp2.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Page1" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Back to MainPage" Height="87" HorizontalAlignment="Left" Margin="26,211,0,0" Name="button1" VerticalAlignment="Top" Width="371" Click="button1_Click" />
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

同样一个按钮。 下面是关键部分了,看如何从MainPage跳到Page1: MainPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneApp2
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //点击按钮跳转到Page1
            NavigationService.Navigate(new Uri("/Page1.xaml?arg1=aaa&arg2=bbb", UriKind.Relative));
            //写过HTML代码一定会觉得很熟悉,参数是一个Uri对象,后面的UriKind.Relative是表示这个是相对路径
        }
    }
}

再从Page1跳回到MainPage,以及接收来自MainPage传过来的参数: Page1.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;

namespace PhoneApp2
{
    public partial class Page1 : PhoneApplicationPage
    {
        public Page1()
        {
            InitializeComponent();
        }
        //重写父类PhoneApplicationPage的 OnNavigatedTo方法,即从其他页面跳转到此时执行
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string arg1 = "";
            string arg2 = "";
            NavigationContext.QueryString.TryGetValue("arg2", out arg2);
            NavigationContext.QueryString.TryGetValue("arg1", out arg1);
            //也可以用NavigationContext.QueryString["args1"]来获取值,但上面的TryGetValue返回的是bool值,相当于try catch语句,可以处理异常,这里没有这样用
            MessageBox.Show("传过来的参数是:arg1=" + arg1+" arg2="+arg2);
            //弹个对话框显示传过来的参数
        }
              
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //点击按钮返回到
            //NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            NavigationService.GoBack();
            //如果使用上面一行的Navigate方法,不会返回到前一页面,而是新创建一个MainPage的实例
           //使用GoBack()之前可以用CanGoBack判断一下是否可返回
        }
    }
}

打包一下源代码: [download id=”22”]

Drawable Bitmap对象生成图片文件的方法:

                Drawable d=main.this.getResources().getDrawable(R.drawable.hot);
                Bitmap bmp=((BitmapDrawable)d).getBitmap();
                //先把Drawable转成Bitmap,如果是Bitmap,就不用这一步了
                FileOutputStream fop;
                try {
                    fop=new FileOutputStream("/sdcard/test.jpg");
                    //实例化FileOutputStream,参数是生成路径
                    bmp.compress(Bitmap.CompressFormat.JPEG, 100, fop);
                    //压缩bitmap写进outputStream 参数:输出格式  输出质量  目标OutputStream
                    //格式可以为jpg,png,jpg不能存储透明
                    fop.close();
                    //关闭流
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

把ImageButton的背景设为透明,效果就相当于插入了一个Image控件,图片后面没有任何背景,而ImageButton默认的显示效果是一个Button,在Button上显示一张图片,图片的背景是一个Button.背景透明方法

ImageButton imgbt=(ImageButton)findViewById(R.id.imgbt);
imgbt.getBackground().setAlpha(0);

先用getBackground()方法得到背景的Drawable对象,再用Drawable对象的setAlpha(int i)方法设置透明度,值为0-255,0为完全透明,255为完全不透明. 接下来是自定义背景和样式的方法: 分别建立两个Drawable类型的xml文件,根结点为selector,一个用于表示不同状态(被按下,没按下)时的背景,一个表示不同状态(被按下,没按下)时的显示的图片.因为两个文件内容只有图片不同,所以只贴一个: imgbt.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/hot" />
    <item android:state_pressed="false" android:drawable="@drawable/joke" />
</selector>

state_pressed就是用来判断是否按钮被按下的.网上其他例子一般都要把android:state_focused也判断一下,但我个人觉得没必要,我只要按下和没按下时显示的图片不同就行了. 当按钮被按下时,显示hot这张图片,没按下时或按下释放时,显示joke这张图片.定义背景的btback.xml内容类似. 下面是Layout的写法:

<ImageButton android:id="@+id/imgbt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/imgbt"
    android:background="@drawable/btback" />

注意,如果用上面的方法背景设为透明,这里就看不到切换背景的效果了.

操作系统 ubuntu 11.04 64bit, jdk 7.0 64bit,下载解压android sdk,Eclipse 指定目录后,提示找不到adb 没有那个文件或目录的解决,到platform-tools下,发现明明就有adb文件,但是终端下执行,还是提示没有那个文件或目录。 其实是因为android sdk是32位程序,需要先安装ia32-libs,才可执行。 终端输入: sudo apt-get install ia32-libs

环境:Ubuntu 11.04+jdk 7.0+eclipse galileo. 确定Jdk已经安装好,并设置好环境变量,在终端可以使用java,javac命令,但打开Eclipse提示找不到JRE。 解决方法:在eclipse.ini里设定JDK路径 添加以下两行: -vm /usr/lib/jvm/java-7-sun/bin/java 其中/usr/lib/jvm/java-7-sun/bin/java 为java路径

用Visual Studio开发Windows Phone7应用,如果想要在Output输出信息,用Console.WriteLine()是看不到的,可以用下面的方法输出:

System.Diagnostics.Debug.WriteLine("Debug OutPut");