把自己的应用设置关联为android系统默认打开程序
2013-04-14 16:32
971 查看
1.首先修改androidmanifest.xml文件
插入下面代码中灰色背景的部分,本例子是使得应用能够查看图片。
你可以根据需要设置data域的mime类型,以支持不同的需求,
2.修改应用的oncreate方法
在oncreate方法中要添加代码获取intent,处理传入的参数。
该方法已经过测试,可行
本文出自 “逆流而上” 博客,请务必保留此出处http://tianya30.blog.51cto.com/6392610/1178031
插入下面代码中灰色背景的部分,本例子是使得应用能够查看图片。
你可以根据需要设置data域的mime类型,以支持不同的需求,
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.frank.setdefault.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*"/> </intent-filter> </activity> </application>
2.修改应用的oncreate方法
在oncreate方法中要添加代码获取intent,处理传入的参数。
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img = (ImageView) findViewById(R.id.imgV); Intent intent = getIntent(); String action = intent.getAction(); if (intent.ACTION_VIEW.equals(action)) { Uri uri = intent.getData(); Log.e("uri", uri.toString()); ContentResolver cr = getContentResolver(); try { Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(uri)); img.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.e("Exception", e.getMessage(),e); } } }
该方法已经过测试,可行
本文出自 “逆流而上” 博客,请务必保留此出处http://tianya30.blog.51cto.com/6392610/1178031
相关文章推荐
- 将程序关联成Android系统默认打开程序
- 将程序关联成Android系统默认打开程序
- 将程序关联成Android系统默认打开程序
- 将程序关联成Android系统默认打开程序
- 将程序关联成Android系统默认打开程序
- 将程序关联成Android系统默认打开程序(Mime Type)
- 将程序关联成Android系统默认打开程序
- Android中设置自己应用为默认打开
- 将程序关联成Android系统默认打开程序
- 通过程序打开Android常用系统设置界面
- JDK6:打开系统关联程序;启动默认浏览器打开网页
- Android 默认启动 默认打开方式 将自己的程序设为默认启动
- 用C#设置应用系统程序的默认输入法
- Android 获取所有已安装应用信息(图标,名称,版本号,包) ,并在自己程序打开某个应用
- 把notepad++设置为系统全局文本默认打开应用
- Android 自己的应用中,跳转到该应用的详细设置页面,设置权限页面--以及跳转到系统的设置页面
- 通过程序打开Android常用系统设置界面
- Android中在自己的程序中打开另一个apk(应用)
- win8怎么设置图片的默认打开方式跳过系统默认程序
- android程序中 直接打开系统设置的锁定屏幕界面