當我將活動附加到「打開方式」列表時,如何才能在Intent中獲取APK文件的路徑?從意圖獲取APK的URI路徑
代碼清單的:
活動<activity
android:name=".InstallActivity"
android:label="@string/title_activity_install"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
</activity>
代碼(InstallActivity.java)
public class InstallActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_install);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
謝謝!