现在的位置: 首页 > 综合 > 正文

Android打开系统自带应用管理画面

2013年07月04日 ⁄ 综合 ⁄ 共 2151字 ⁄ 字号 评论关闭

MainActivity如下:

package cc.testsetting;

import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.app.Activity;
import android.content.Intent;
/**
 * Demo描述:
 * 跳转到系统自带的应用管理画面
 * 或者跳转到系统自带的应用管理画面下的某个App的管理画面
 * 
 * 参考资料:
 * http://jykenan.iteye.com/blog/1654925
 * Thank you very much
 */
public class MainActivity extends Activity {
   private Button mManageAppButton;
   private Button mManageAppsButton;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		init();
	}
	
	private void init(){
		mManageAppButton=(Button) findViewById(R.id.manageAppButton);
		mManageAppButton.setOnClickListener(new ClickListenerImpl());
		mManageAppsButton=(Button) findViewById(R.id.manageAppsButton);
		mManageAppsButton.setOnClickListener(new ClickListenerImpl());
	}
	
	private class ClickListenerImpl implements OnClickListener{
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.manageAppButton:
				Intent manageAppIntent = new Intent(); 
				manageAppIntent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
				//第二个参数为包名
				Uri uri = Uri.fromParts("package", "cc.testsetting", null); 
				manageAppIntent.setData(uri); 
				startActivity(manageAppIntent); 
				break;

			case R.id.manageAppsButton:
				Intent manageAppsIntent =  new Intent();  
				manageAppsIntent.setAction("android.intent.action.MAIN");  
				manageAppsIntent.setClassName("com.android.settings", "com.android.settings.ManageApplications");  
			    startActivity(manageAppsIntent);  
				break;

			default:
				break;
			}

		}
		
	}

}

 

main.xml如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <Button
        android:id="@+id/manageAppButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="ManageApp"
        android:layout_marginTop="120dip" 
    />
    
    <Button
        android:id="@+id/manageAppsButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="ManageApps"
        android:layout_marginTop="250dip" 
    />
    

</RelativeLayout>

 

抱歉!评论已关闭.