flash swf游戏专为安卓app的方法?

13分钟前阅读1回复0
wojiukan
wojiukan
  • 管理员
  • 注册排名1
  • 经验值2618280
  • 级别管理员
  • 主题523656
  • 回复0
楼主

《如何把网页上的SWF小游戏下载下来与操作步骤》\n\n要实现从网页上下载并直接在安卓应用中运行SWF小游戏,需要以下步骤:\n\n下载SWF文件并创建APK版本\n\n如果你只拥有SWF文件,并且没有经过反编译或导出源代码,那么目前在没有更新的Adobe Flash或CC环境下是无法转化为APK文件的,你需要使用一款能够反编译和导出源代码的工具,如CCleaner或Unrar,以下是进行这项操作的步骤:

  • 安装CCleaner或Unrar:分别可以在Chrome扩展商店(Chrome Web Store)、Microsoft Store、Debian repository或Fedora repository下载对应版本的CCleaner或Unrar。
  • 打开CCleaner/Unrar,双击Install CCleaner(安装CCleaner)或Install Unrar(安装Unrar)。
  1. 找到并替换SWF文件中的application/x-shockwave-flash扩展名:

    • 找到所有SWF文件的扩展名为application/x-shockwave-flash的文件,并检查这些文件是否都是有效的Adobe Flash文件,在Finder或Google Chrome的“File Explorer”窗口中,点击文件夹图标或文件列表,然后按住Ctrl键点击SWF文件名,拖拽文件到左侧的搜索框,同时在右侧按下Shift + F组合键查找并替换为application/vnd.adobe.flex.js.
    • 在命令行中,输入以下命令以确认更改成功:
      find . -name "*.swf" -type f \
          | xargs rename --newname "*.flex.js"
  2. 创建APK文件\n\n保存修改后的SWF文件到相应的存储介质(如Android Studio或Android Studio生成的APK文件),在项目根目录下创建一个新的AVD(应用程序开发设备)或模拟器,例如Android-Studio,以下是在Android Studio中创建APK的步骤:

    • 打开Android Studio,点击顶部菜单栏的“New Project”按钮创建新项目。
    • 在“Empty Activity”视图中,填写项目名称(如"GameActivity"),在XML标签中添加以下资源:
<activity
    android:name=".GameActivity"
    android:label="@string/app_name">
    <!-- 游戏逻辑代码 goes here -->
</activity>
  • build.gradle(AndroidManifest.xml)文件中添加必要的权限,例如权限android.permission.WRITE_EXTERNAL_STORAGE

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  • 创建Java类文件,继承Application类并重写onCreate()方法,将以下代码替换为你自己的代码片段,将src/main/res/layout中的main路径更改为你的工程路径,如src/main/res/layout/activity_main.xml

    public class GameActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // ...
        // 将SWF文件中的URL替换为APK文件的完整路径
        String path = "path_to_your_apk_file";
        File apkFile = new File(path);
        try (InputStream fis = apkFile.getInputStream()) {
          this.loadContent(fis);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      private void loadContent(InputStream fis) throws IOException {
        // ...
        // 取得动画对象
        AnimationSet animationSet = new AnimationSet();
        // 设置帧速率和播放模式
        animationSet.setDuration(1000);
        animationSet.setFillAfter(true);
        // 添加开始帧
        MovieClipContainer clipContainer = new MovieClipContainer();
        clipContainer.doAnimation(new Start(), 0, 100, 100, 0, 100, 100);
        animationSet.addFrame("start");
        // 添加中间帧
        MovieClipContainer clipMiddle = new MovieClipContainer();
        clipMiddle.doAnimation(new MidFrame(), 100, 150, 100, 0, 150, 150);
        animationSet.addFrame("mid");
        // 添加结束帧
        MovieClipContainer clipEnd = new MovieClipContainer();
        clipEnd.doAnimation(new End(), 200, 170, 100, 0, 200, 170);
        animationSet.addFrame("end");
        animationSet.playTogether(clipsContainer, clipMiddle, clipEnd);
        // 设置动画的显示方式
        Stage stage = findViewById(R.id.stage);
        stage.removeAllViews();
        for (int i = 0; i < animationSet.getNumberOfFrames(); i++) {
          Animation keyframe = animationSet.getKeyframes(i);
          KeyframeGroup group = new KeyframeGroup(keyframe);
          group.getKeyframeTimes().addAll(range(0, 2));
          group.getChildren().addKeyframe(keyframe);
          group.addToStage(stage);
        }
      }
    }
  • 创建Java UI组件,例如一个进度条用于跟踪下载进度:

    ProgressBar progressBar = findViewById(R.id.progress_bar);
    progressBar.setMaxDownloadSize(bytesToTransfer);
    updateProgress(bytesToTransfer);
  • 添加网络请求库,例如OkHttp or Volley to make HTTP requests to the下载的APK file:

    NetworkManager manager = (NetworkManager) getSystemService(Context.NETWORK_SERVICE);
    if (!manager.isNetworkAvailable()) {
      Toast.makeText(this, "No internet connection available", Toast.LENGTH_SHORT).show();
      return;
    }
    RequestQueue requestQueue = manager.newRequestQueue();
    HttpUrl url = new HttpUrl.Builder()
        .append("http://www.your_url_to_apk_file.com/download")
        .build();
    HttpGet httpGET = new HttpGet(url.toString());
    requestQueue.add(requestGET);
    int bytesTransferred = 0;
    while ((bytesTransferred = httpGET.sendRequest()) != 0 && !requestQueue.isFull()) {
      progressBar.incrementProcessed(1);
      notifyProgressUpdate(bytesTransferred / bytesToTransfer * 100);
    }
    requestQueue.shutdown();
  1. 将APK文件发布到App Store\n\n根据Android Developer Documentation提供的指导,将APK文件发布到Apple App Store的过程大致分为以下步骤:

    • 确保您的AndroidManifest.xml文件包含了com.example.YOUR_PACKAGE_NAME.FIXED_VERSIONcom.example.YOUR_PACKAGE_NAME:minVersion(取决于您发布的API版本)的声明和应用的权限请求:

      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.YOUR_PACKAGE_NAME">
        <!-- ... -->
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
        <!-- ... -->
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <!-- ... -->
        <application
          android:name=".YOUR_PACKAGE_NAME"
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme">
          <!-- ... -->
          <receiver
            android:name=".BootReceiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
              <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
            <!-- ... -->
          </receiver>
          <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <!-- ... -->
            <service
              android:name=".DownloadingService"
              android:exported="false">
              <!-- ... -->
            </service>
          </activity>
        </application>
      </manifest>
    • 运行adb shell pm release-app com.example.YOUR_PACKAGE_NAME.apk命令发布APK文件。

    • 如果使用Xcode作为开发者工具进行打包和分发,则按照以下步骤进行:

      1. 打开Xcode项目文件(.xcworkspace),并导航至Archive -> Export Build Products to iOS Device.
      2. 选择发布的目标设备,如iPhone Xs Max,选择适当的构建配置。
      3. iOS Simulator页面,点击 -> New, 输入设备型号、iOS版本号和关联APK文件的位置(确保在相同的目录结构中,如com.example.YOUR_PACKAGE_NAME下的APP文件夹)。
      4. Your Application Package Name字段中输入您的应用名称,选择相应的框架,如APK (iOS),并设置SDK版本号(如果未预先导入)。
      5. 设定其他发布选项,如数据包大小限制、广告标识、压缩选项等。
      6. 点击Finish, Copy Bundle Path,这将复制当前应用包的完整路径。
      7. 长按“Products”,选择“Product”,屏幕上方会出现一个向导,允许您
0
回帖

flash swf游戏专为安卓app的方法? 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息