你们需要发现这一意图可由系统处理。
public static boolean canHandleIntent(final Context context, final Intent intent) {
if (intent != null) {
final PackageManager pm = context.getPackageManager();
if (pm != null) {
if (pm.queryIntentActivities(intent, 0).size() > 0) {
return true;
}
}
}
return false;
}
If that returns false you should prompt the user to download the app from the market.
Call,
//Market.getViewPackageOnMarket("org.otherapp.sketchapp");
public class Market {
public static final String Application_BaseMarketUri = "market://details?id=";
public static final Intent getViewPackageOnMarket(final String package_name) {
final Intent result = new Intent(Intent.ACTION_VIEW);
result.setData(Uri.parse(Application_BaseMarketUri + package_name));
return result;
}
}
你们也需要开始使用 活动 因此,在您的发起活动中,你需要补充这些内容。
public class MyKillerAppActivity extends Activity {
// Declare constant for the activity result.
public static final int ACTIVITYRESULT_GETSKETCH = 1;
// Call the activity ....
public void someMethod() {
startActivityForResult(intent, ACTIVITYRESULT_GETSKETCH);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK) {
if(requestCode == ACTIVITYRESULT_GETSKETCH) {
handleGetSketchResult(data);
} /* Handle other results if you need to. */
}
}
}
这是一种口号,但还有人! 你们需要解释数据来源。 我不知道这种格式是用篮子对你进行回顾,但这里就是一个如何从美术馆获取数据的例子。 该美术馆把你带回一个内容提供者所在地,以装上用户所收集的形象。 该法典从内容提供者处查找档案,然后打开档案,将其装入一个供使用的比图。
public static Bitmap onActivityResult_getImage(Context context, Intent data) {
Bitmap result = null;
Uri dataUri = data.getData();
final String filePath = findPictureFilePath(context, dataUri);
if(filePath != null) {
result = BitmapFactory.decodeFile(filePath);
}
return result;
}
private static String findPictureFilePath(Context context, Uri dataUri) {
String filePath = null;
final String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(dataUri, projection, null, null, null);
int data_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if(cursor.moveToFirst()) {
filePath = cursor.getString(data_index);
}
} finally {
if(cursor != null) {
cursor.close();
}
}
return filePath;
}