Android调用系统功能、apk安装卸载

1、安装apk

String dirPath = "/data/data/" + getPackageName() + "/files/test.apk"; //文件需有可读权限
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);


2、卸载apk

方法一(已测试):

Uri packageUri = Uri.parse("package:" + appUnit.pname);
Intent deleteIntent = new Intent();
deleteIntent.setAction(Intent.ACTION_DELETE);
deleteIntent.setData(packageUri);
context.startActivity(deleteIntent);


方法二(未测试):

 private void startUninstall(final String pkg) {
  if (!InstallUtils.isApkInstalled(mContext, pkg)) {
   Toast.makeText(mContext, "程序未安装,无需卸载!", Toast.LENGTH_SHORT).show();
   return;
  } else {
   Uri packageURI = Uri.parse("package:" + pkg);
   Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
   startActivity(uninstallIntent);
  }
 }



3. 启动Android默认浏览器(已测试

  

  Intent intent= new Intent();        
    intent.setAction("android.intent.action.VIEW");    
    Uri content_url = Uri.parse("http://www.cnblogs.com");   
    intent.setData(content_url);  
    startActivity(intent);

这样子,android就可以调用起手机默认的浏览器访问。

以下内容均来自转载。未经测试。

附带电话号码(调用系统短信):

[java]  view plain copy
  1. Intent mIntent = new Intent(Intent.ACTION_VIEW);    
  2.             mIntent.putExtra("address",phoneNum);    
  3.             mIntent.putExtra("sms_body""");    
  4.             mIntent.setType("vnd.android-dir/mms-sms");    
  5.             context.startActivity(mIntent);    

附带短信内容(调用系统短信):

[java]  view plain copy
  1. Uri smsToUri = Uri.parse("smsto:");// 联系人地址  
  2.             Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO,  
  3.                     smsToUri);  
  4.             mIntent.putExtra("sms_body",  
  5.                     "abcdefgh");// 短信内容  
  6.             context.startActivity(mIntent);  
附带邮件内容(调用系统邮件):

[java]  view plain copy
  1. Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  
  2.             // 文本格式  
  3.             emailIntent.setType("text/plain");  
  4.             // 对方邮件地址  
  5.             emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");  
  6.             // 标题内容  
  7.             emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");  
  8.             // 邮件文本内容  
  9.             emailIntent  
  10.                     .putExtra(android.content.Intent.EXTRA_TEXT,  
  11.                             "abcdefgh");  
  12.             context.startActivity(Intent.createChooser(emailIntent,  
  13.                     "Choose Email Client"));  

调用系统添加联系人:

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_INSERT,  
  2.                     Contacts.CONTENT_URI);  
  3.             intent.putExtra("name""");  
  4.             intent.putExtra("phone", number);  
  5.             context.startActivity(intent);  
调用系统添加或编辑联系人:

[java]  view plain copy
  1. Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);  
  2.             intent.setType("vnd.android.cursor.item/contact");  
  3.             intent.putExtra(Intents.Insert.PHONE, number);  
  4.             context.startActivity(intent);  
调用系统编辑联系人:

[java]  view plain copy
  1. Intent i = new Intent(Intent.ACTION_EDIT);   
  2.         i.setData(ContentUris.withAppendedId(ContactsContract.Contacts.CONTE

你可能感兴趣的:(android,apk,系统,intent)