Twitterの共有ボタンを設定して、後でdrawableから写真を共有して動的に変更しますネットからこのコードを取得してアプリに貼り付けます次のエラーnullポインター例外が発生し、それを理解できません助けていただければ幸いですありがとうございました。
enter code here
ImageView twittersharing =(ImageView)findViewById(R.id.twitter_sharing);
twittersharing.setOnClickListener(new View.OnClickListener()
{
private Context context;
@Override
public void onClick(View arg0)
{
//Toast.makeText(getBaseContext(), "On click", Toast.LENGTH_SHORT).show();
// TODO Auto-generated method stub
File filePath = context.getFileStreamPath("placeholder.jpg");
share("com.twitter.android",filePath.toString());
}
});
public void share(String nameApp, String imagePath)
{
try
{
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpg");
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty())
{
for (ResolveInfo info : resInfo)
{
Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
targetedShare.setType("image/jpg"); // put here your mime type
if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo");
targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by ME");
targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)) );
targetedShare.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
}
catch(Exception e)
{
Log.v("VM","Exception while sending image on" + nameApp + " "+ e.getMessage());
}
}