안드로이드에서 WPS 호출

9157 단어
프로젝트는 wps를 호출하여 오피스 문서를 보아야 하기 때문에 인터넷에서 관련 자료를 찾았는데 인터페이스 문서를 찾지 못해 일부분만 찾을 수 있었다. 한참을 찾았는데 마지막에 홈페이지에서 APi 문서를 찾았다. 지금은 정리해서 블로그로 써서 나중에 보기 편리하게 했다.
문서의 필드 이름 중 일부를 정리했습니다.
package com.houjianbo.wpsdemo;

public class WpsModel {
	public static final String OPEN_MODE = "OpenMode";//        。
	public static final String SEND_SAVE_BROAD = "SendSaveBroad";//            。
	public static final String SEND_CLOSE_BROAD = "SendCloseBroad";//            
	public static final String THIRD_PACKAGE = "ThirdPackage";//       ,          。
	public static final String CLEAR_BUFFER = "ClearBuffer";//              。
	public static final String CLEAR_TRACE = "ClearTrace";//              。
	public static final String CLEAR_FILE = "ClearFile";//               。
	public static final String VIEW_PROGRESS = "ViewProgress";//          。
	public static final String AUTO_JUMP = "AutoJump";//               。
	public static final String SAVE_PATH = "SavePath";//       。
	public static final String VIEW_SCALE = "ViewScale";//             。
	public static final String VIEW_SCALE_X = "ViewScrollX";//           X  。
	public static final String VIEW_SCALE_Y = "ViewScrollY";//           Y  。
	public static final String USER_NAME = "UserName";//      。
	public static final String HOMEKEY_DOWN = "HomeKeyDown";//   home     
	public static final String BACKKEY_DOWN = "BackKeyDown";//   back     
	public static final String ENTER_REVISE_MODE = "EnterReviseMode";//          
	public static final String CACHE_FILE_INVISIBLE = "CacheFileInvisible";// Wps             

	public class OpenMode {
		public static final String NORMAL = "Normal";//     
		public static final String READ_ONLY = "ReadOnly";//     
		public static final String READ_MODE = "ReadMode";//            
															//  Word、TXT    
		public static final String SAVE_ONLY = "SaveOnly";//     (    ,  ,  )
															//  Word、TXT    
	}

	public class ClassName {
		public static final String NORMAL = "cn.wps.moffice.documentmanager.PreStartActivity2";//    
		public static final String ENGLISH = "cn.wps.moffice.documentmanager.PreStartActivity2";//    
		public static final String ENTERPRISE = "cn.wps.moffice.documentmanager.PreStartActivity2";//    
	}

	public class PackageName {
		public static final String NORMAL = "cn.wps.moffice_eng";//    
		public static final String ENGLISH = "cn.wps.moffice_eng";//    
	}

	public class Reciver {
		public static final String ACTION_BACK = "com.kingsoft.writer.back.key.down";//      
		public static final String ACTION_HOME = "com.kingsoft.writer.home.key.down";// Home   
		public static final String ACTION_SAVE = "cn.wps.moffice.file.save";//     
		public static final String ACTION_CLOSE = "cn.wps.moffice.file.close";//       
	}

}
, , 。 , , :
package com.houjianbo.wpsdemo;

import java.io.File;

import com.houjianbo.wpsdemo.WpsModel.ClassName;
import com.houjianbo.wpsdemo.WpsModel.OpenMode;
import com.houjianbo.wpsdemo.WpsModel.PackageName;
import com.houjianbo.wpsdemo.WpsModel.Reciver;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	private Button tv;
	String stringPath;
	MyBroadCastReciver receiver;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		tv = (Button) findViewById(R.id.editor);
		
	

		stringPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/test.docx";
		System.out.println("StringPath:"+stringPath);
		tv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				boolean flag = openFile(stringPath);
				if (flag == true) {
					
					Toast.makeText(MainActivity.this,"       ", 2000).show();
				}else{
					Toast.makeText(MainActivity.this, "      ", 2000).show();
				}
			}
		});
	}
	
	boolean openFile(String path) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		bundle.putString(WpsModel.OPEN_MODE, OpenMode.NORMAL); //     
		bundle.putBoolean(WpsModel.SEND_CLOSE_BROAD, true); //          
		bundle.putString(WpsModel.THIRD_PACKAGE, getPackageName()); //         ,            
		bundle.putBoolean(WpsModel.CLEAR_TRACE, true);//       
		// bundle.putBoolean(CLEAR_FILE, true); //         
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.setAction(android.content.Intent.ACTION_VIEW);
		intent.setClassName(PackageName.NORMAL, ClassName.NORMAL);

		File file = new File(path);
		if (file == null || !file.exists()) {
			System.out.println("         ");
			return false;
		}

		Uri uri = Uri.fromFile(file);
		intent.setData(uri);
		intent.putExtras(bundle);
		try {
			startActivity(intent);
		} catch (ActivityNotFoundException e) {
			System.out.println("  wps  :"+e.toString());
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		//unregisterReceiver(receiver);
		
	}
}


, :
package com.houjianbo.wpsdemo;




import com.houjianbo.wpsdemo.WpsModel.ClassName;
import com.houjianbo.wpsdemo.WpsModel.PackageName;
import com.houjianbo.wpsdemo.WpsModel.Reciver;




import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.sax.StartElementListener;

public class MyBroadCastReciver extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {
  
  switch (intent.getAction()) {
  case Reciver.ACTION_BACK://     
   System.out.println(Reciver.ACTION_BACK);
   break;
  case Reciver.ACTION_CLOSE://         
   System.out.println(Reciver.ACTION_CLOSE);
  
   break;
  case Reciver.ACTION_HOME://home   
   System.out.println(Reciver.ACTION_HOME);

   break;
  case Reciver.ACTION_SAVE://    
   System.out.println(Reciver.ACTION_SAVE);

   break;
  default:
   break;
  }

 }

}





, , , :



    

    
        
            
                

                
            
        
        
        
           
                
                
                
                

            
        
    




wps office , , :
       , , , wps , , , ? , intent , wps , , , ? , , , .....

: http://download.csdn.net/detail/houjianbo188/9519763

좋은 웹페이지 즐겨찾기