|
package com.example.mysocialintent.libs; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
import java.net.URLDecoder; |
|
|
|
import android.app.Activity; |
|
import android.content.Intent; |
|
|
|
|
|
public enum MySocialIntent { |
|
INSTANCE; |
|
public Intent getIntent(Activity activity, String content, String key){ |
|
return getIntent(activity, content, content, key); |
|
} |
|
|
|
public Intent getIntent(Activity activity, String content, String subject, String key){ |
|
Intent intent = new Intent(Intent.ACTION_SEND); |
|
intent.putExtra(Intent.EXTRA_TEXT, decoder(content)); |
|
intent.putExtra(Intent.EXTRA_SUBJECT, decoder(subject)); |
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
intent.setFlags(0x3000000); |
|
intent.setType("text/plain"); |
|
|
|
Kinds self = Kinds.other.getType(key); |
|
intent = self.addProperValue(intent); |
|
|
|
return intent; |
|
} |
|
|
|
private String decoder(String content){ |
|
String value = ""; |
|
try{ |
|
if(content != null) |
|
value = URLDecoder.decode(content, "utf-8"); |
|
}catch(UnsupportedEncodingException e){ |
|
} |
|
return value; |
|
} |
|
|
|
private enum Kinds { |
|
twitter{ |
|
String packageName = "com.twitter.android"; |
|
String className = "com.twitter.android.PostActivity"; |
|
public Intent addProperValue(Intent intent){ |
|
intent.setClassName(packageName, className); |
|
return intent; |
|
} |
|
}, |
|
gplus{ |
|
String packageName = "com.google.android.apps.plus"; |
|
String className = "com.google.android.apps.plus.app.ViewStreamActivity"; |
|
public Intent addProperValue(Intent intent){ |
|
intent.setClassName(packageName, className); |
|
return intent; |
|
} |
|
}, |
|
line{ |
|
String packageName = "jp.naver.line.android"; |
|
String className = "jp.naver.line.android.activity.selectchat.SelectChatActivity"; |
|
public Intent addProperValue(Intent intent){ |
|
intent.setClassName(packageName, className); |
|
return intent; |
|
} |
|
}, |
|
other{ |
|
public Intent addProperValue(Intent intent){ |
|
return intent; |
|
} |
|
}; |
|
public Kinds getType(String key){ |
|
for(Kinds instance: Kinds.values()){ |
|
if(instance.name().equals(key)){ |
|
return instance; |
|
} |
|
} |
|
return other; |
|
} |
|
abstract public Intent addProperValue(Intent intent); |
|
} |
|
} |
Hello brother,
Have you manage to get the S/N of LG device?