`
wang_peng1
  • 浏览: 3902155 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

安装或卸载一个apk以及简单发动一个网页

阅读更多

这里可以参看http://www.anddev.org/viewtopic.php?p=23928

权限之类的不比说了

Java: 
URL sourceUrl = new URL(source); 
Object data = sourceUrl.getContent(); 
String fileName = sourceUrl.getFile().substring(fileName.lastIndexOf('/') + 1); 
// create/open file in the 'data/data/<app namespace>/files' directory 
FileOutputStream fos = openFileOutput(fileName, Context.MODE_PRIVATE); 
int read = 0; 
byte[] buffer = new byte[512]; 
BufferedInputStream bis = new BufferedInputStream((InputStream) data); 
do{ 
     read = bis.read(buffer); 
     if(read > 0){ 
          fos.write(buffer, 0, read); 
     } 
}while(read != -1); 

 

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
哲理诗关键 装的
  <activity android:name=".PackageInstallerActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="content" />
                <data android:scheme="file" />
                <data android:mimeType="application/vnd.android.package-archive" />
            </intent-filter>
        </activity>
卸载的
 <activity android:name=".UninstallerActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.DELETE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="package" />
            </intent-filter>
        </activity>
2.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://Yoururl.com"))); 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics